0
0
Cprogramming~20 mins

Pointers to pointers in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pointer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A10
BAddress of p
CAddress of x
DCompilation error
Attempts:
2 left
💡 Hint
Remember that *p points to x, so **pp dereferences p to get x's value.
Predict Output
intermediate
2: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;
}
A5
B20
CAddress of a
DCompilation error
Attempts:
2 left
💡 Hint
Changing **pp changes the value of a through the pointers.
🔧 Debug
advanced
2: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;
}
ASegmentation fault at runtime
BCompilation error: missing semicolon
CPrints 100
DCompilation error: incompatible types in assignment
Attempts:
2 left
💡 Hint
Check the type of the right side and left side in the assignment to pp.
🧠 Conceptual
advanced
1: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?
A3
B2
C4
D1
Attempts:
2 left
💡 Hint
Each * removes one level of pointer indirection.
Predict Output
expert
3: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;
}
A100\n100\n100
B50\n200\n300
C100\n200\n300
DCompilation error
Attempts:
2 left
💡 Hint
Each assignment changes the value of val through different levels of pointers.