Creating and Using Pointers

We first need to declare a pointer cell:

     int *px;

How do we use a pointer cell?

All operations with pointers can be done with just two operators:
* & - the address of operator
* * - the indirection or dereference operator
     int x,y;
     int * px;

     x = 5;
     px = &x;

     printf("x = %d\n", x);
     printf("x = %d\n", *px);

     y = *px;
     printf("y = %d\n", y);

     *px = 10;

     printf("x = %d\n", x);
     printf("x = %d\n", *px);

     px = &y;
     *px = 15;

     printf("x = %d\n", x);
     printf("y = %d\n", y);
     printf("what = %d\n", *px);

There are only a few things we need to remember to use pointers.


[up] to Overview.