An array is just about the simplest and most useful thing you can think of. Imagine a line of boxes numbered 0 to N, where N is some arbitrary number. To put something in the fifth box, you walk over to the one with the number 4 (because they start at 0), and drop the thing in it. Then you walk back to the beginning of the row. To get the thing back, you walk back to the box with 4 and grab the thing.
Let's say that thing is a number, 123. The C++ code to create a line of ten boxes numbered 0 to 9 is:
int box[10]; You can then put the thing in the fifth box like this:
box[4] = 123; Then to get the thing back, you do the same thing, except with a spare box on the left, which we'll call thing:
int thing = box[4]; If you want every thing in the line of boxes, you go from one end to the other and grab the things in each box:
for ( int i = 0; i < 10; i++ )
std::cout<< box[i] <<'\n'; Or you could go from the other end:
for ( int i = 9; i >= 0; i-- )
std::cout<< box[i] <<'\n'; Just about any use of an array is some variation of the above.