Pointer Operations
Just what can you do with pointers? C offers five basic operations you can perform on pointers, and the next program demonstrates these possibilities. To show the results of each operation, we will print the value of the pointer (which is the address it points to), 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.10 shows the five basic operations that can be performed with or on pointer variables.
Listing 10.10 The pt_ops.c program.
/* pt_ops.c -- pointer operations */ #include <stdio.h> int main(void) { int urn[3] = {100,200,300}; int * ptr1, * ptr2; ptr1 = urn; /* assign an ... |
Get C Primer Plus®, Third 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.