0
0
Cprogramming~10 mins

Pointers to pointers in C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Pointers to pointers
Declare int variable
Declare pointer to int
Declare pointer to pointer to int
Assign int address to pointer
Assign pointer address to pointer to pointer
Access value via pointer
Access value via pointer to pointer
This flow shows how a variable's address is stored in a pointer, and that pointer's address is stored in a pointer to pointer, allowing access to the original value through two levels of indirection.
Execution Sample
C
int x = 10;
int *p = &x;
int **pp = &p;
printf("%d\n", **pp);
This code declares an int, a pointer to it, and a pointer to that pointer, then prints the int value via the pointer to pointer.
Execution Table
StepVariableValueActionOutput
1x10Declare int x with value 10
2paddress of xAssign p = &x
3ppaddress of pAssign pp = &p
4**pp10Dereference pp twice to get x's value10
5Program ends
💡 Program ends after printing the value 10 accessed via pointer to pointer
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
xundefined10101010
pundefinedundefinedaddress of xaddress of xaddress of x
ppundefinedundefinedundefinedaddress of paddress of p
Key Moments - 2 Insights
Why do we need a pointer to a pointer instead of just a pointer?
A pointer to a pointer stores the address of a pointer variable, allowing us to indirectly access or modify the original pointer. See step 3 and 4 in the execution_table where pp holds p's address, and **pp accesses x's value.
What does **pp mean in the code?
**pp means dereferencing twice: first to get the pointer p stored at pp, then to get the value x pointed to by p. This is shown in step 4 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of p after step 2?
A10
Baddress of x
Caddress of p
Dundefined
💡 Hint
Check the 'Value' column for variable p at step 2 in the execution_table
At which step does **pp give the value 10?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the 'Variable' and 'Output' columns in the execution_table for **pp
If we change x to 20 after step 1, what will **pp output at step 4?
A10
Baddress of x
C20
Daddress of p
💡 Hint
Refer to variable_tracker to see how x's value affects **pp output
Concept Snapshot
Pointers to pointers in C:
- int *p stores address of int variable
- int **pp stores address of pointer p
- Access value via **pp (double dereference)
- Useful for indirect pointer manipulation
- Syntax: int **pp = &p;
Full Transcript
This example shows how pointers to pointers work in C. First, an integer variable x is declared with value 10. Then, a pointer p stores the address of x. Next, a pointer to pointer pp stores the address of p. When we use **pp, we dereference twice: first to get p, then to get x's value. The program prints 10 by accessing x through pp. This helps understand how multiple levels of pointers allow indirect access to variables.