Challenge - 5 Problems
Pointer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pointer to pointer dereferencing
What is the output of this C program?
C
#include <stdio.h> int main() { int x = 10; int *p = &x; int **pp = &p; printf("%d\n", **pp); return 0; }
Attempts:
2 left
💡 Hint
Remember that *p points to x, so **pp dereferences p to get x's value.
✗ Incorrect
The variable pp is a pointer to p, which itself points to x. So **pp accesses the value of x, which is 10.
❓ Predict Output
intermediate2:00remaining
Value after modifying through pointer to pointer
What is the output of this program?
C
#include <stdio.h> int main() { int a = 5; int *p = &a; int **pp = &p; **pp = 20; printf("%d\n", a); return 0; }
Attempts:
2 left
💡 Hint
Changing **pp changes the value of a through the pointers.
✗ Incorrect
Since **pp points to a, assigning 20 to it changes a to 20. So printing a outputs 20.
🔧 Debug
advanced2:00remaining
Identify the error in pointer to pointer usage
What error does this code produce when compiled?
C
#include <stdio.h> int main() { int x = 100; int *p = &x; int **pp = p; printf("%d\n", **pp); return 0; }
Attempts:
2 left
💡 Hint
Check the type of the right side and left side in the assignment to pp.
✗ Incorrect
The variable pp is declared as int ** but assigned p which is int *. This causes a type mismatch error during compilation.
🧠 Conceptual
advanced1:30remaining
Number of indirections in pointer to pointer
Given
int ***ppp;, how many times must you dereference ppp to get the integer value it ultimately points to?Attempts:
2 left
💡 Hint
Each * removes one level of pointer indirection.
✗ Incorrect
ppp is a pointer to a pointer to a pointer to an int. So you must dereference it three times (***ppp) to get the int value.
❓ Predict Output
expert3:00remaining
Output of complex pointer to pointer manipulation
What is the output of this program?
C
#include <stdio.h> int main() { int val = 50; int *p1 = &val; int **p2 = &p1; int ***p3 = &p2; ***p3 = 100; printf("%d\n", val); **p2 = 200; printf("%d\n", val); *p1 = 300; printf("%d\n", val); return 0; }
Attempts:
2 left
💡 Hint
Each assignment changes the value of val through different levels of pointers.
✗ Incorrect
All three assignments modify val through different pointer levels. So the printed values are 100, then 200, then 300.