Arrays
We have used arrays in our preceding examples, but we have not really provided a formal definition for that useful-yet-low-level construct. Note that in this section, the term “array” refers to raw, built-in arrays, not to other very useful but higher-level constructs such as std::vector<T> or std::array<T,N>.
Quite simply, in C++, an array is a contiguous sequence of elements of the same type. Thus, in the following excerpt, the a0 object occupies 10*sizeof(int) bytes in memory, whereas the a1 object occupies 20*sizeof(std::string) bytes:
int a0[10]; std::string a1[20];
The number of bytes between elements at indices i and i+1 in an array of some type T is precisely equal to sizeof(T).
Consider the following expression, which would be used in C++, as in C, for some array arr:
arr[i]
It evaluates to the same address as the following:
*(arr + i)
Since pointer arithmetic is typed, the + i part in this expression means “plus...