3.6 RELATIONSHIP BETWEEN ARRAY AND POINTER
Internally all arrays (of any dimension) make use of pointers for their implementation. In C/C++, the
array name is treated as the address of its first element.
For example,
int a[20];
Here, ‘a’ is the name of the array that holds 80 integer numbers and the value of ‘a’ is the address
of num[0] (i.e., the address of the first element of the array); then, (a + 1) contains the address of the
2nd element, (a +2) contains an address of the 3rd element, and so on. This is because the C++
compiler internally reserves 40 words for a 20-array element. However, you can also access the
address of array elements as &a[0], &a[1], &a[2], and so on.
Do'stlaringiz bilan baham: |