Bird
Raised Fist0
Cprogramming~20 mins

Pointer declaration - 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 declaration and usage
What is the output of this C code snippet?
C
#include <stdio.h>

int main() {
    int x = 10;
    int *p = &x;
    printf("%d\n", *p);
    return 0;
}
AAddress of x
B0
C10
DCompilation error
Attempts:
2 left
💡 Hint
Remember that *p means the value pointed to by p.
❓ Predict Output
intermediate
1:30remaining
Value of pointer variable after declaration
What is the value of the pointer variable p after this code runs?
C
int x = 5;
int *p = &x;
AUndefined value
BThe address of x
CThe value 5
DNULL
Attempts:
2 left
💡 Hint
Pointers store addresses, not values directly.
📝 Syntax
advanced
1:30remaining
Identify the correct pointer declaration
Which of the following is a correct declaration of a pointer to an integer?
Aint *p;
Bint p*;
Cint &p;
Dpointer int p;
Attempts:
2 left
💡 Hint
The asterisk * goes before the pointer name to declare a pointer.
🧠 Conceptual
advanced
2:00remaining
Pointer declaration with multiple variables
What is the type of variables a and b after this declaration? int *a, b;
Aa is a pointer to int; b is an int
Ba and b are both pointers to int
Ca and b are both ints
Da is an int; b is a pointer to int
Attempts:
2 left
💡 Hint
The asterisk applies only to the variable it precedes.
🔧 Debug
expert
2:30remaining
Find the error in pointer declaration
What error does this code produce? int *p; *p = 10;
C
int *p;
*p = 10;
ANo error, prints 10
BCompilation error: missing semicolon
CType error: incompatible types
DSegmentation fault or undefined behavior
Attempts:
2 left
💡 Hint
p is declared but not initialized before dereferencing.

Practice

(1/5)
1. What does the following declaration mean in C?
int *ptr;
easy
A. ptr is a pointer to a character variable
B. ptr is a pointer to an integer variable
C. ptr is an integer variable
D. ptr is a function returning an integer

Solution

  1. Step 1: Understand the * symbol in declaration

    The * before ptr means ptr is a pointer variable, not a normal integer.
  2. Step 2: Check the type before *

    The type before * is int, so ptr points to an integer variable.
  3. Final Answer:

    ptr is a pointer to an integer variable -> Option B
  4. Quick Check:

    int *ptr means pointer to int [OK]
Hint: Look for * before variable name to identify pointer [OK]
Common Mistakes:
  • Thinking * means multiplication here
  • Confusing pointer with normal variable
  • Ignoring the type before *
2. Which of the following is the correct way to declare a pointer to a float variable in C?
easy
A. ptr float*;
B. float ptr*;
C. *float ptr;
D. float *ptr;

Solution

  1. Step 1: Recall pointer declaration syntax

    Pointer declaration syntax is: type *name; so the * goes between type and variable name.
  2. Step 2: Check each option

    float *ptr; matches correct syntax: float *ptr; others have wrong order or missing parts.
  3. Final Answer:

    float *ptr; -> Option D
  4. Quick Check:

    Pointer syntax = type *name; [OK]
Hint: Always put * between type and variable name [OK]
Common Mistakes:
  • Placing * after variable name
  • Putting * before type
  • Missing * entirely
3. What is the output of this C code?
int x = 10;
int *p = &x;
printf("%d", *p);
medium
A. 10
B. Compilation error
C. Garbage value
D. Address of x

Solution

  1. Step 1: Understand pointer initialization

    p is assigned the address of x using &x, so p points to x.
  2. Step 2: Dereference pointer to get value

    *p means value at address p, which is x's value 10.
  3. Final Answer:

    10 -> Option A
  4. Quick Check:

    *p gives value at pointer address [OK]
Hint: Use * to get value from pointer address [OK]
Common Mistakes:
  • Printing pointer p instead of *p
  • Confusing address and value
  • Forgetting & to get address
4. Identify the error in this pointer declaration:
int *p;
p = 5;
medium
A. Error: assigning integer directly to pointer
B. Correct: p points to integer 5
C. Error: missing * in assignment
D. Error: pointer must be initialized with & operator

Solution

  1. Step 1: Check pointer assignment rules

    A pointer must hold a memory address, not a direct integer value.
  2. Step 2: Analyze given assignment

    Assigning 5 directly to pointer p is invalid; it should be an address like &variable.
  3. Final Answer:

    Error: assigning integer directly to pointer -> Option A
  4. Quick Check:

    Pointer = address, not direct value [OK]
Hint: Pointers store addresses, never assign raw values directly [OK]
Common Mistakes:
  • Assigning integer instead of address
  • Forgetting & operator for address
  • Confusing pointer and normal variable
5. Given the code below, which pointer declaration correctly allows modifying the value of num through the pointer?
int num = 20;
// Which declaration is correct?
hard
A. int *ptr = num;
B. int ptr = #
C. int *ptr = #
D. int &ptr = num;

Solution

  1. Step 1: Understand pointer declaration for modifying variable

    To modify num via pointer, pointer must hold address of num, declared as int *ptr.
  2. Step 2: Check each option

    int *ptr = # correctly declares pointer to int and assigns address of num. Others are invalid syntax or wrong types.
  3. Final Answer:

    int *ptr = # -> Option C
  4. Quick Check:

    Pointer to int = &variable for modification [OK]
Hint: Use int *ptr = &var to modify var via pointer [OK]
Common Mistakes:
  • Assigning value instead of address
  • Using wrong type for pointer
  • Confusing references with pointers
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