The variables we have worked with before this chapter could hold only one value at a time. In this chapter, you learned about an array, which permits you to use a single variable to store many values. The values are stored at consecutive indexes, starting with zero and then incrementing by one for each additional element of the array.
The data type of an array may be integer, float, or character. However, a particular array cannot contain integers, floats, and characters . All the elements of an array must be of the same data type.
You need to declare an array before you can use it. The syntax for declaring an array is almost identical to the syntax for declaring integer, character, or other variables. The only difference between declaring a single scalar variable and an array of scalar variables is that, when declaring an array, the variable name is followed by a number within square brackets. That number is the arrays size declarator.
The size declarator must be a literal or a constant. A literal is a value that is written exactly as it is meant to be interpreted. A constant is a name that represents the same value throughout a program. You learned in this chapter how to declare and use a constant.
You also can create an array through initialization. Initialization is when you assign a value to a variable in the same statement in which you declare that variable, as contrasted to assignment, which is when you assign a value to a variable in a statement after the one in which you declare that variable.
You have two alternative methods of initializing an array. The first alternative is explicit array sizing, in which the square brackets contain a numerical constant that explicitly specifies the size of the array. The second alternative is implicit array sizing , in which the square brackets are empty and the size of the array is indicated implicitly by the number of elements on the right side of the assignment operator.
You learned in this chapter how to assign values to an array using a loop. You also learned how to use the cin objects get and getline functions to assign values to a character array.
Finally, you learned how to pass an array as a function argument. When you do so, the argument is being passed by address.