0
0
Cprogramming~20 mins

Address and dereference operators - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pointer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
A20
B10
CAddress of x
DCompilation error
Attempts:
2 left
💡 Hint
Remember that *p accesses the value at the address stored in p.
Predict Output
intermediate
2: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;
}
AAddress of a
BAddress of p
C5
DCompilation error
Attempts:
2 left
💡 Hint
**pp means dereference twice: first to get p, then to get a's value.
🔧 Debug
advanced
2: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;
}
APrints 10
BCompilation error: uninitialized pointer
CPrints garbage value
DSegmentation fault at runtime
Attempts:
2 left
💡 Hint
Consider what happens when you dereference an uninitialized pointer.
📝 Syntax
advanced
1:30remaining
Correct pointer declaration syntax
Which option correctly declares a pointer to an integer variable?
Aint *p;
Bint &p;
Cint p*;
Dpointer int p;
Attempts:
2 left
💡 Hint
In C, the * symbol is used to declare a pointer.
🚀 Application
expert
2: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;
}
A10
B30
C20
DCompilation error
Attempts:
2 left
💡 Hint
Pointer arithmetic moves the pointer by multiples of the data type size.