A pointer to a pointer is a variable that stores the address of another pointer variable. It allows indirect access to the value pointed to by the first pointer.
Click to reveal answer
beginner
How do you declare a pointer to a pointer for an int variable?
You declare it as int **ptr; where ptr is a pointer to a pointer to an int.
Click to reveal answer
intermediate
Given int x = 10; and int *p = &x;, how do you declare and assign a pointer to pointer pp?
Declare int **pp = &p;. Now pp points to p, which points to x.
Click to reveal answer
intermediate
How do you access the value of x using the pointer to pointer pp?
Use **pp to get the value of x. The first * gets the pointer p, the second * gets the value x.
Click to reveal answer
advanced
Why are pointers to pointers useful in C programming?
They are useful for dynamic memory management, passing pointers by reference to functions, and handling multi-dimensional arrays or complex data structures.
Click to reveal answer
What does int **pp; declare?
AA pointer to an int
BA pointer to a pointer to an int
CAn int variable
DA pointer to a char
✗ Incorrect
int **pp; means pp is a pointer to a pointer to an int.
If int x = 5; and int *p = &x;, what is the type of &p?
Aint **
Bint &
Cint
Dint *
✗ Incorrect
&p is the address of p, which is a pointer to int, so its type is int **.
How do you access the value of x using a pointer to pointer pp?
A*pp
B&pp
Cpp
D**pp
✗ Incorrect
Using **pp dereferences twice to get the value of x.
Which of the following is a valid assignment for a pointer to pointer?
Aint **pp = p;
Bint **pp = &x;
Cint **pp = &p;
Dint **pp = x;
✗ Incorrect
pp must store the address of a pointer variable like p, so int **pp = &p; is correct.
Why might you pass a pointer to pointer to a function?
ATo modify the pointer itself inside the function
BTo pass an integer value
CTo avoid using pointers
DTo declare a new variable
✗ Incorrect
Passing a pointer to pointer lets the function change the original pointer's value (e.g., allocate memory).
Explain what a pointer to pointer is and how you declare one in C.
Think about a pointer that points to another pointer.
You got /3 concepts.
Describe how to access the value of an int variable using a pointer to pointer.
Remember each * removes one level of indirection.
You got /3 concepts.
Practice
(1/5)
1. What does a pointer to a pointer store in C?
easy
A. The size of a variable
B. The value of an integer
C. The address of another pointer
D. The address of a function
Solution
Step 1: Understand pointer basics
A pointer stores the address of a variable.
Step 2: Understand pointer to pointer
A pointer to pointer stores the address of another pointer, not a direct value.
Final Answer:
The address of another pointer -> Option C
Quick Check:
Pointer to pointer = address of pointer [OK]
Hint: Pointer to pointer holds address of pointer, not value [OK]
Common Mistakes:
Confusing pointer to pointer with pointer to value
Thinking it stores the value directly
Mixing it with function pointers
2. Which of the following is the correct way to declare a pointer to a pointer to an int in C?
easy
A. int **ptr;
B. int ptr*;
C. int *ptr*;
D. int &ptr*;
Solution
Step 1: Recall pointer declaration syntax
Single pointer to int is declared as int *ptr;.
Step 2: Extend to pointer to pointer
Pointer to pointer uses two asterisks: int **ptr;.
Final Answer:
int **ptr; -> Option A
Quick Check:
Pointer to pointer declaration uses two * [OK]
Hint: Use two * for pointer to pointer declaration [OK]
Common Mistakes:
Placing * incorrectly in declaration
Using & instead of *
Confusing pointer syntax with references
3. What is the output of the following C code?
int x = 10;
int *p = &x;
int **pp = &p;
printf("%d", **pp);
medium
A. Address of x
B. Compilation error
C. Address of p
D. 10
Solution
Step 1: Understand variable assignments
x = 10, p points to x, pp points to p.
Step 2: Evaluate **pp
*pp gives p (pointer to x), **pp gives value at x, which is 10.
Final Answer:
10 -> Option D
Quick Check:
**pp dereferences twice to get x's value [OK]
Hint: Double dereference **pp gets original value [OK]
Common Mistakes:
Printing pointer address instead of value
Using single * instead of **
Confusing *p and **pp
4. Identify the error in the following code snippet:
int x = 5;
int *p = &x;
int **pp;
*pp = p;
printf("%d", **pp);
medium
A. Syntax error in printf
B. pp is not initialized before dereferencing
C. x is not initialized
D. p is not assigned correctly
Solution
Step 1: Check pointer initialization
pp is declared but not initialized to point anywhere.
Step 2: Analyze dereferencing *pp = p;
Dereferencing uninitialized pp causes undefined behavior or crash.
Final Answer:
pp is not initialized before dereferencing -> Option B