C/C++ Arena

Step 1 of 6

Declare and index

An array is a fixed-size row of values of the same type, stored next to each other in memory.

int ammo[3] = {30, 20, 7};
printf("%d\n", ammo[0]);   // 30, indexes start at 0
ammo[2] = 8;               // change the last one

An array of size 3 has valid indexes 0, 1, 2. ammo[3] is out of bounds. C won't stop you, and the result is undefined behaviour.

Your turn: print the first and the last element of the array.

Next: Loop over an array