SE250:HTTB:Pointers:Pointers to pointers
Jump to navigation
Jump to search
<html>
<image src="http://www.rajithaonline.com/SE250/httb/pointers/final/p_to_p_head.png" width="445" height="92" alt="Pointers to Pointers Header Logo" /> |
</html>
Previous Page | Contents | Next Page |
Pointers to Pointers
Named "double indirection"
"indirection" refers to indirect actions eg. an action is performed on the address to which a pointer points to. "double indirection" means indirect action on an indirect action
- Syntax is similar
Declarations use an extra " * " eg.
int **ptr
meaning pointer to a pointer of int, or address of pointer is stored in another pointer
Example:
First declaring 3 int objects:
- A number 2
- Pointer to int
- Pointer to a pointer to int
int num = 2; int *ptrONE; int **ptrTWO;
Points the first pointer to the number 2
ptrONE = #
Points the second pointer to the first pointer
ptrTWO = &ptrONE;
This concept can be applied as many times as you want.
Example: Pointer to pointer of a pointer
int num = 2; int *ptrONE int **ptrTWO int ***ptrTHREE ptrONE = # ptrTWO = &ptrONE; ptrTHREE = &ptrTWO;
Previous Page | Contents | Next Page |