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]; ...

Get C Primer Plus, Fourth Edition 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.