Bird
Raised Fist0
Cprogramming~20 mins

Pointers to pointers in C - Practice Problems & Coding Challenges

Choose your learning style10 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.

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

  1. Step 1: Understand pointer basics

    A pointer stores the address of a variable.
  2. Step 2: Understand pointer to pointer

    A pointer to pointer stores the address of another pointer, not a direct value.
  3. Final Answer:

    The address of another pointer -> Option C
  4. 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

  1. Step 1: Recall pointer declaration syntax

    Single pointer to int is declared as int *ptr;.
  2. Step 2: Extend to pointer to pointer

    Pointer to pointer uses two asterisks: int **ptr;.
  3. Final Answer:

    int **ptr; -> Option A
  4. 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

  1. Step 1: Understand variable assignments

    x = 10, p points to x, pp points to p.
  2. Step 2: Evaluate **pp

    *pp gives p (pointer to x), **pp gives value at x, which is 10.
  3. Final Answer:

    10 -> Option D
  4. 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

  1. Step 1: Check pointer initialization

    pp is declared but not initialized to point anywhere.
  2. Step 2: Analyze dereferencing *pp = p;

    Dereferencing uninitialized pp causes undefined behavior or crash.
  3. Final Answer:

    pp is not initialized before dereferencing -> Option B
  4. Quick Check:

    Dereferencing uninitialized pointer causes error [OK]
Hint: Always initialize pointers before dereferencing [OK]
Common Mistakes:
  • Assuming pointer auto-initializes
  • Ignoring uninitialized pointer usage
  • Confusing pointer assignment with value assignment
5. Given the code below, what will be the output?
int a = 3, b = 7;
int *p1 = &a;
int *p2 = &b;
int **pp = &p1;
*pp = p2;
printf("%d %d", *p1, *p2);
hard
A. 7 7
B. 3 7
C. 3 3
D. Compilation error

Solution

  1. Step 1: Initial pointer assignments

    p1 points to a (3), p2 points to b (7), pp points to p1.
  2. Step 2: Change p1 via pointer to pointer

    *pp = p2 changes p1 to point to b (7).
  3. Step 3: Print values

    *p1 now points to b (7), *p2 is 7, so output is "7 7".
  4. Final Answer:

    7 7 -> Option A
  5. Quick Check:

    Pointer to pointer changed p1 to point to b [OK]
Hint: Pointer to pointer can change pointer target [OK]
Common Mistakes:
  • Assuming p1 still points to a
  • Confusing *pp and **pp
  • Ignoring pointer reassignment effect
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard