Page t040, go to NEXT,
PREVIOUS, INDEX
Pointers Arithmetic
A pointer can point to element of an array
float x[5];
float *y = &x[0];
float *z = x;
- y is a pointer to x[0]
- z is also a pointer to
x[0]
- y+1 is pointer to x[1]
- thus *(y+1) and x[1]
access the same object
- y[1] is shorthand for
*(y+1)
- integer add, subtract and relational operators are allowed on pointers
What's wrong here?
float x[5];
float* y, z;
y = x; /* OK */
z = x; /* WRONG */
- z is a float and not a
float *
C Course, 22-jan-1997,
Peter Klok,
pfk@hef.kun.nl