Pointers
Equivalence of Arrays and Pointers
- In C and C++ the name of an array specified without a subscript
denotes a pointer to the first element of the array
- For example, in the following statement:
int int_array[1000];
The variable name int_array refers to the address of
int_array[0]
int_array is not a valid lvalue, but int_array[0]
is
- A pointer is just an address (or integer) and we can perform
arithmetic oprations on it
int_array+i and &int_array[i] are equivalent
*(int_array + i) and int_array[i] are equivalent
- Consider the following code:
int int_array[1000], *b;
b = int_array;
After the first statement, int_array[0] is defined but
b[0]
is not
After the second statement, b[0] is valid and has the same
contents as
int_array[0]
[] have a higher precedence than &
b is an lvalue while int_array is not. Statements of
the form
int_array = ... are not correct
Back to Previous Page
Document:
Local Date:
Last Modified On: