8.9. Relationship Between Pointers and Built-In Arrays

Built-in arrays and pointers are intimately related in C++ and may be used almost interchangeably. Pointers can be used to do any operation involving array subscripting.

Assume the following declarations

int b[ 5 ]; // create 5-element int array b; b is a const pointerint *bPtr; // create int pointer bPtr, which isn't a const pointer

We can set bPtr to the address of the first element in the built-in array b with the statement

bPtr = b; // assign address of built-in array b to bPtr

This is equivalent to assigning the address of the first element as follows:

bPtr = &b[ 0 ]; // also assigns address of built-in array b to 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.