C Pointer to Pointer
1. What is a Pointer to Pointer?
-
A pointer to pointer points to a pointer variable, which in turn points to another variable.
-
It’s like two levels of indirection:
Syntax:
-
data_type→ type of variable being pointed to -
**→ indicates double pointer
2. Example: Basic Pointer to Pointer
Output (example):
*pptr→ value ofptr(address ofnum)**pptr→ value ofnum
3. Pointer to Pointer with Functions
-
Pointers to pointers are used for modifying pointers inside functions.
Output:
Passing
&ptrallows the function to modify the pointer itself, not just the value it points to.
4. Pointer to Pointer with Arrays of Pointers
-
Useful for arrays of strings:
Output:
ptris a pointer to the first string pointer.
5. Key Points About Pointer to Pointer
-
Declared using
data_type **ptr2;. -
*ptr2gives the value of the first pointer. -
**ptr2gives the value of the actual variable. -
Useful for:
-
Modifying pointers inside functions
-
Arrays of strings
-
Dynamic memory allocation (double pointers for 2D arrays)
-
