⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e03-01.cpp

📁 游戏开发数据结构Data Structures for Game Programmers
💻 CPP
字号:
// =======================================================
//  Chapter 3, Example 1
//  Demonstrating Static Arrays.
// =======================================================


// -------------------------------------------------------
// Name:        ArrayFunction
// Description: sets array[0] to 10.
// Arguments:   - p_array: the array
// -------------------------------------------------------
void ArrayFunction( int p_array[] )
{
    p_array[0] = 10;
}



void main()
{
    // declare an array with 10 cells.
    int array1[10];

    // declare x
    int x;

    // set the first cell to 5, then set the second
    // cell to the first cell.
    array1[0] = 5;
    array1[1] = array1[0];

    // DONT EVER DO THIS:
    // this next line of code writes past the end
    // of the array, potentially causing harm.
    // array1[10] = 0;


    // pass the array to a function.
    ArrayFunction( array1 );

    // set cell 5 to 42.
    array1[5] = 42;

    // retrieve the value of cell 5 using 3 different methods.
    // x should be 42 after each operation.
    x = array1[5];
    x = *( array1 + 5 );
    x = 5[array1];



    // declare a second array and initialise it.
    int array2[5] = { 1, 2, 3, 4, 5 };

    // declare a third array and initilise it without a specific size
    int array3[] = { 1, 2, 3, 4, 5, 6 };


    // retrieve the number of cells in array3:
    int size = sizeof( array3 ) / sizeof( int );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -