12.4 POINTERS AND ARRAYS
The pointer finds its power when working with arrays. It can work with arrays in a very friendly manner. Consider the following declarations:
int marks[10];
int *p ;
We have declared an array of 10 elements of type integer and a pointer pointing to type integer. Now we set p to point to first array element by
p = &marks[0];
Now *p means marks[0]. Pointer p contains the address of the first array element. If you say (p+3) it will mean you are referring to address of marks[3]. If you say *(p+3) it will mean marks[3]. Our language gives you a still better method of referencing array elements. It allows you to say p[7]. It means marks[7]. Is it not interesting? Use this facility with caution. p[7] is provided to you as shorthand ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.