December 2013
Beginner
576 pages
16h 4m
English
Just as you can assign initial values to variables when they are declared, you can assign initial values to the elements of an array. This is done by simply listing the initial values of the array, starting from the first element. Values in the list are separated by commas, and the entire list is enclosed in a pair of braces.
The statement
int integers[5] = { 0, 1, 2, 3, 4 } ;
sets the value of integers[0] to 0, integers[1] to 1, integers[2] to 2, and so on.
Arrays of characters are initialized in a similar manner; thus, the statement
char letters[5] = { 'a', 'b', 'c', 'd', 'e' } ;
defines the character array letters and initializes the five elements to ...
Read now
Unlock full access