Challenge - 5 Problems
Pointer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pointer dereference after assignment
What is the output of this C code snippet?
C
#include <stdio.h> int main() { int x = 10; int *p = &x; *p = 20; printf("%d", x); return 0; }
Attempts:
2 left
💡 Hint
Remember that *p accesses the value at the address stored in p.
✗ Incorrect
The pointer p points to x. Changing *p changes x's value to 20, so printing x outputs 20.
❓ Predict Output
intermediate2:00remaining
Value printed by pointer to pointer
What value does this program print?
C
#include <stdio.h> int main() { int a = 5; int *p = &a; int **pp = &p; printf("%d", **pp); return 0; }
Attempts:
2 left
💡 Hint
**pp means dereference twice: first to get p, then to get a's value.
✗ Incorrect
pp points to p, which points to a. So **pp accesses the value of a, which is 5.
🔧 Debug
advanced2:00remaining
Identify the error in pointer assignment
What error does this code produce when compiled?
C
#include <stdio.h> int main() { int x = 10; int *p; *p = x; printf("%d", *p); return 0; }
Attempts:
2 left
💡 Hint
Consider what happens when you dereference an uninitialized pointer.
✗ Incorrect
Pointer p is declared but not initialized to a valid address. Dereferencing it causes a runtime segmentation fault.
📝 Syntax
advanced1:30remaining
Correct pointer declaration syntax
Which option correctly declares a pointer to an integer variable?
Attempts:
2 left
💡 Hint
In C, the * symbol is used to declare a pointer.
✗ Incorrect
Option A uses correct C syntax for declaring a pointer to int. Others are invalid syntax.
🚀 Application
expert2:30remaining
Predict the output of pointer arithmetic and dereference
What is the output of this program?
C
#include <stdio.h> int main() { int arr[] = {10, 20, 30}; int *p = arr; printf("%d", *(p + 2)); return 0; }
Attempts:
2 left
💡 Hint
Pointer arithmetic moves the pointer by multiples of the data type size.
✗ Incorrect
p points to arr[0]. Adding 2 moves to arr[2], which is 30. Dereferencing prints 30.