August 2001
Beginner
482 pages
10h 52m
English
In C++ an array name is a constant pointer to the first element of the array. Therefore, in the declaration
CAT Family[50];
Family is a pointer to &Family[0], which is the address of the first element of the array Family.
It is legal to use array names as constant pointers, and vice versa. Therefore, Family + 4 is a legitimate way of accessing the data at Family[4].
The compiler does all the arithmetic when you add to, increment, and decrement pointers. The address accessed when you write Family + 4 isn't 4 bytes past the address of Family—it is four objects past it. If each object is 4 bytes long, Family + 4 is 16 bytes. If each object is a CAT that has four long member variables of 4 bytes each and two short member ...
Read now
Unlock full access