Bird
0
0

Find the error in this C code snippet:

medium📝 Debug Q14 of 15
C - Operators and Expressions
Find the error in this C code snippet:
int x = 5;
int y = 10;
if (x = y) {
    printf("Equal");
} else {
    printf("Not Equal");
}
AThe if statement syntax is incorrect
BThe '=' operator should be '==' for comparison
CThe printf statements are missing semicolons
DThe variables x and y are not declared
Step-by-Step Solution
Solution:
  1. Step 1: Identify the operator used in the if condition

    The code uses '=' which is assignment, not comparison.
  2. Step 2: Correct operator for comparison in C

    Use '==' to compare values, '=' assigns value.
  3. Final Answer:

    The '=' operator should be '==' for comparison -> Option B
  4. Quick Check:

    Use '==' to compare, '=' to assign [OK]
Quick Trick: Use '==' for comparison, not '=' [OK]
Common Mistakes:
  • Using '=' instead of '==' in conditions
  • Ignoring missing semicolons (not the error here)
  • Confusing assignment with comparison

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes