Bird
0
0

Identify the error in this C code snippet:

medium📝 Debug Q6 of 15
C - Basics and Execution Environment
Identify the error in this C code snippet:
int main() {
    int a = 5;
    int *p;
    *p = a;
    return 0;
}
AVariable a is not declared
BMissing semicolon after int *p
CPointer p is not initialized before dereferencing
DReturn type of main is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check pointer initialization

    Pointer p is declared but not assigned an address before use.
  2. Step 2: Understand dereferencing uninitialized pointer

    Dereferencing p without initialization causes undefined behavior or crash.
  3. Final Answer:

    Pointer p is not initialized before dereferencing -> Option C
  4. Quick Check:

    Uninitialized pointer dereference = Error [OK]
Quick Trick: Always initialize pointers before using * to avoid errors [OK]
Common Mistakes:
  • Ignoring pointer initialization
  • Thinking variable a is undeclared
  • Assuming missing semicolon causes error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes