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 = 10;
int y = 3;
int z = x / y.0;
printf("%d", z);
AUsing a floating-point number in integer division
BIncorrect format specifier in printf
CMissing semicolon after variable declaration
DDivision by zero error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the division expression

    The expression x / y.0 uses y.0 which attempts a floating-point literal but causes invalid syntax, as x and y are integers.
  2. Step 2: Understand the syntax error

    Using y.0 causes a compilation error due to invalid syntax in the integer division context.
  3. Final Answer:

    Using a floating-point number in integer division -> Option A
  4. Quick Check:

    Integer division must use integers only [OK]
Quick Trick: Integer division needs integer operands only [OK]
Common Mistakes:
  • Thinking printf format is wrong
  • Ignoring the decimal in y.0
  • Assuming division by zero

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes