September 1998
Intermediate to advanced
848 pages
20h 13m
English
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.
/* pt_ops.c -- pointer operations */ #include <stdio.h> int main(void) { int urn[3] = {100,200,300}; int * ptr1, * ptr2; ptr1 = urn; /* assign an ... |
Read now
Unlock full access