0
0
Cprogramming~20 mins

Pointers and arrays in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pointer and Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pointer arithmetic with arrays
What is the output of this C code snippet?
C
#include <stdio.h>

int main() {
    int arr[] = {10, 20, 30, 40};
    int *p = arr;
    printf("%d\n", *(p + 2));
    return 0;
}
A30
B20
C40
D10
Attempts:
2 left
💡 Hint
Remember that pointer arithmetic moves by the size of the data type.
Predict Output
intermediate
2:00remaining
Value of pointer after increment
What will be the value printed by this code?
C
#include <stdio.h>

int main() {
    char str[] = "hello";
    char *p = str;
    p++;
    printf("%c\n", *p);
    return 0;
}
Ah
Bo
Cl
De
Attempts:
2 left
💡 Hint
Incrementing a pointer moves it to the next character.
🔧 Debug
advanced
2:00remaining
Identify the error in pointer usage
What error does this code produce when compiled or run?
C
#include <stdio.h>

int main() {
    int *p;
    *p = 5;
    printf("%d\n", *p);
    return 0;
}
ACompilation error: uninitialized pointer
BPrints 5
CSegmentation fault (runtime error)
DUndefined behavior but no error
Attempts:
2 left
💡 Hint
Consider what happens when you dereference a pointer that has not been assigned a valid address.
Predict Output
advanced
2:00remaining
Output of pointer to array and sizeof
What is the output of this code?
C
#include <stdio.h>

int main() {
    int arr[5] = {1,2,3,4,5};
    int (*p)[5] = &arr;
    printf("%zu\n", sizeof(p));
    return 0;
}
A8
B20
C4
D5
Attempts:
2 left
💡 Hint
sizeof(p) gives the size of the pointer, not the array it points to.
🧠 Conceptual
expert
2:00remaining
Number of elements accessed via pointer arithmetic
Given the code below, how many elements of the array can be safely accessed using the pointer p?
C
#include <stdio.h>

int main() {
    int arr[4] = {10, 20, 30, 40};
    int *p = arr + 1;
    // How many elements can be accessed safely via p?
    return 0;
}
A4
B3
C2
D1
Attempts:
2 left
💡 Hint
Pointer p points to the second element. Count elements from there to the end.