O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pointer Operations

Just what can you do with pointers? C offers six basic operations you can perform on pointers, and the next program demonstrates these possibilities. To show the results of each operation, the program prints the value of the pointer (which is the address to which it points), the value stored in the pointed-to address, and the address of the pointer itself. (If your compiler doesn't support the %p specifier, try %u or perhaps %lu for printing the addresses.)

Listing 10.13 shows the six basic operations that can be performed with pointer variables.

Listing 10.13. The pt_ops.c Program
 #include <stdio.h> int main(void) { int urn[3] = {100,200,300}; int * ptr1, * ptr2; ptr1 = urn; // assign an address to a pointer ptr2 = &urn[2]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required