Arrays in C++ are contiguous blocks of memory space used to store multiple elements of the same type. For example, int a[5] is an array that stores 5 integer variables. A pointer, on the other hand, is like a “road sign” pointing to a specific memory address, which can record the location of a variable or array element.
What Address Does the Array Name Represent?¶
When you define an array, the system allocates a contiguous block of space in memory. For example:
int a[5] = {5, 15, 25, 35, 45};
Each element in the array has its own address. Suppose the address of the first element a[0] is 0x7ffeefbff500, then the address of a[1] is 0x7ffeefbff504 (since an int typically occupies 4 bytes of memory space), and so on.
Key Point: The array name a itself represents the address of the first element of the array! In other words, the value of a is the same as `&a[