Bird
0
0

Identify the error in this C code snippet:

medium📝 Debug Q6 of 15
C - Operators and Expressions
Identify the error in this C code snippet:
int a = 3, b = 4;
if (a = b) {
printf("Equal");
}
ANo error, code is correct
BMissing semicolon after printf
CIncorrect variable declaration
DUsing assignment '=' instead of comparison '=='
Step-by-Step Solution
Solution:
  1. Step 1: Check the if condition

    The condition uses '=' which assigns b to a, not compares them.
  2. Step 2: Correct operator usage

    To compare, '==' should be used. Using '=' causes unintended assignment and always true condition.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' -> Option D
  4. Quick Check:

    Use '==' for comparison, not '=' [OK]
Quick Trick: Use '==' in conditions, '=' is assignment [OK]
Common Mistakes:
  • Confusing '=' and '=='
  • Ignoring compiler warnings
  • Assuming '=' compares values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes