Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use | Resource CD

 

Addresses of Arrays

apvector <double> grade(100);

The elements of this array can be referred to in a program as
 grade[0] . . . grade[99]
When the program is compiled, the compiler does not save the addresses of all of the elements, but only saves the address of the first element, grade[0]
When the program needs to access any element, such as grade[1], it calculates the address by adding units to the address of grade[0].
 The number of bytes in each unit is equal to the number of bytes required to store an element of the array.  In this example, the number of bytes in each unit is 8 bytes (needed to store a double).

The address of grade[0] can be obtained by using the 
& ("address of") operator.

In C++, the name of the array, grade, without a
subscript, is the same as &grade[0].

computerpoint
The name of the array is the address of the first element of the array.

 

        cout<< grade;  //will print the address of first element of
                               // the array, assuming no other variable is 
                               // defined as 'grade'.

 

 

Mantra:  "The name of the array is the address of the first element of the array.
Ohmmm......."


Chant the mantra......

 

 

ampersand (&)
"address of"