Arrays

Arrays are a good way of compactly storing variables that have the same type.

#include <stdio.h>

int main()
{
    int x[] = {1, 2, 3, 4, 5, 6};
    int y[10];
    int z[10][10];

    int a = 0;
    int b = 0;

    for(a = 0; a < 6; a++)
    {
        printf("x[%i]: %i\n", a, x[a]);
    }

    for(a = 0; a < 10; a++)
    {
        y[a] = a;
        printf("y[%i]: %i\n", a, y[a]);
    }

    for(a = 0; a < 10; a++)
    {
        for(b = 0; b < 10; b++)
        {
            z[a][b] = (a * 10) + b;
            printf("z[%i][%i]: %i\n", a, b, z[a][b]);
        }
    }

    return 0;
}

The first array to be declared is the x array. In this case it is assigned initial values 1 to 6 for all 6 entries in the array (the amount of entries in the array is inferred from the amount of values declared). The first for loop loops through the array and prints all 6 values.

The second array to be declared is the y array. It is explicitly declared to have 10 entries. The initial values of these 10 entries are not declared (it is usually assigned to all 0). The second for loop assigns values to all 10 entries and prints that value.

The third array to be declared is the z array. It is a multi-dimensional array, in this case 2D (a 10 x 10 array). Like our y array, the initial values are not declared. The third for loop is a double for loop that assigns values 0 to 99 to all 100 entries in the array and prints it. If you have problems seeing this, remember that for the first row, a * 10 is 0 * 10 = 0 (assuming a is rows and b is columns).