Demonstrating the Relationship Between Pointers and Built-In Arrays

Figure 8.17 uses the four notations discussed in this section for referring to built-in array elements—array subscript notation, pointer/offset notation with the built-in array’s name as a pointer, pointer subscript notation and pointer/offset notation with a pointer—to accomplish the same task, namely displaying the four elements of the built-in array of ints named b.

 1   // Fig. 8.17: fig08_17.cpp 2   // Using subscripting and pointer notations with built-in arrays. 3   #include <iostream> 4   using namespace std; 5  6   int main() 7   { 8      int b[] = { 10, 20, 30, 40 }; // create 4-element built-in array b 9      int *bPtr = b; // set bPtr ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.