October 2011
Beginner to intermediate
1200 pages
35h 33m
English
C++ has several rules about initializing arrays. They restrict when you can do it, and they determine what happens if the number of array elements doesn’t match the number of values in the initializer. Let’s examine these rules.
You can use the initialization form only when defining the array. You cannot use it later, and you cannot assign one array wholesale to another:
int cards[4] = {3, 6, 8, 10}; // okayint hand[4]; // okayhand[4] = {5, 6, 7, 9}; // not allowedhand = cards; // not allowed
However, you can use subscripts and assign values to the elements of an array individually.
When initializing an array, you can provide fewer values than array ...
Read now
Unlock full access