Multiple choice technology programming languages

What will be the output of the following: void main() { float a=0.7; if(a<0.7) printf("c++"); else printf("c"); }

  1. c++

  2. c

  3. Compile time error

  4. None of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Float 0.7 is stored as 0.699999... due to binary representation. Literal 0.7 in the if condition becomes double (more precise). Comparison: 0.699999 < 0.700000 → true, so c++ prints. This demonstrates floating-point precision issues.

AI explanation

The literal 0.7 in the comparison a &lt; 0.7 is a double, while a is declared as a float. When the float value 0.7 is stored, it gets rounded to the nearest representable float, and that value, once promoted to double for the comparison, is not exactly equal to the double literal 0.7 — it ends up slightly smaller. So a &lt; 0.7 evaluates true and "c++" is printed, illustrating a classic floating-point precision pitfall rather than a logic error.