Bird
0
0

Identify the error in this C code snippet:

medium📝 Debug Q6 of 15
C - Variables and Data Types
Identify the error in this C code snippet:
void func() {
    printf("%d", x);
    int x = 10;
}
AMissing semicolon after printf
BVariable x used before declaration
CFunction func missing return type
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage order

    Variable x is used in printf before it is declared, which is not allowed in C.
  2. Step 2: Confirm syntax correctness

    Semicolon is present, function return type is void, so no other errors.
  3. Final Answer:

    Variable x used before declaration -> Option B
  4. Quick Check:

    Use before declaration causes error [OK]
Quick Trick: Declare variables before using them [OK]
Common Mistakes:
  • Ignoring order of declaration and usage
  • Thinking C allows use before declaration
  • Confusing function return type with variable scope

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes