Tip:A–D to answerE for explanationV for videoS to reveal answer
What will be the output of the following C code?
int a = 10;
if (a == 5)
printf("true");
else
printf("false");
- A.
true
- B.
false
(Correct Answer) - C.
error
- D.
none
Explanation
Solution
The correct answer is (b) false.
Logic using LaTeX:
-
Variable Initialization: The variable a is assigned the value 10, so a=10.
-
Condition Check: The if statement uses the comparison operator ==. It evaluates whether a is equal to 5.
-
Substitution: Substituting the value, we get the expression (10==5).
-
Result: Since 10 is not equal to 5, the expression evaluates to False (or 0 in C logic).
-
Execution: Because the if condition is false, the code skips the if block and executes the else block, printing "false".