An array's name is an address
When finding the address of a scalar variable (or a structure),
we precede the name by the address of operator,
the ampersand:
int total;
int *p = &total ;
|
However, when requiring the address of an array,
we're really asking for the address of the first element of that array:
#define N 5
int totals[N];
int *first = &totals[0]; // the first element of the array
int *second = &totals[1]; // the second element of the array
int *third = &totals[2]; // the third element of the array
|
As we frequently use a pointer to traverse the elements of an array
(see the following slides on pointer arithmetic),
we observe the following equivalence:
int *p = &totals[0] ;
// and:
int *p = totals ;
|
That is: "an array's name is synonymous with the address of the first
element of that array".
CITS2002 Systems Programming, Lecture 11, p6, 26th August 2024.
|