Page t038, go to NEXT,
PREVIOUS, INDEX
Dereferencing Pointers
Consider
#include <stdio.h>
int main ()
{
int *p;
int j = 4;
p = &j;
printf ("%d\n", *p);
*p = 5;
printf ("%d %d\n", *p, j);
if (p != 0)
{ printf ("Pointer p points at %d\n", *p);
}
return 0;
}
- *p dereferences pointer to access object pointed at
- *p can be used on either side of assignment
operator
- if p is equal to 0, then pointer is pointing at
nothing and is called a null pointer
- dereferencing a null pointer causes a core dump :-(
C Course, 21-jan-1997,
Peter Klok,
pfk@hef.kun.nl