Memory Accessing Operators
The operators in Table 1-14 are used to access objects in memory. The terms used here, such as pointer, array, structure, etc., are introduced later under Section 1.10.
Operator |
Meaning |
Example |
Result |
& |
Address of |
&x |
A constant pointer to |
* |
Indirection |
*p |
The object (or function) pointed to by |
[ ] |
Array element |
x[i] |
|
. |
Member of a structure or union |
s.x |
The member named |
-> |
Member of a structure or union |
p->x |
The member named |
The operand of the address operator
&
must be an expression that designates a
function or an object. The address operator &
yields the address of its operand. Thus an expression of the form
&x
is a pointer to x
. The
operand of &
must not be a bit-field, nor a
variable declared with the storage class specifier
register
.
The indirection operator
*
is
used to access an object or a function through a pointer. If
ptr
is a pointer to an object or function, then
*ptr
designates the object or function pointed to
by ptr
. For example:
int a, *pa; // An int variable and a pointer to int. pa = &a; // Let pa point to a. *pa = 123; // Now equivalent to a = 123;
The subscript operator
[]
can
be used to address the elements of an array. If v
is an array and i
is an integer, then
v[i]
denotes the element with index
i
in the array. In more general ...
Get C Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.