Find the output of this program. main() { int i=5; printf(“%d”,i=++i ==6); }
-
6
-
1
-
5
-
Compiler error
Reveal answer
Fill a bubble to check yourself
B
Correct answer
Explanation
The expression i=++i 6 has two parts: ++i increments i to 6, then the comparison 66 evaluates to 1 (true). The assignment i=1 stores 1 in i. printf outputs 1. The claimed answer B is correct.
AI explanation
To find the output of the given program, let's go through each step:
- The variable
iis initialized with a value of 5. - The
printffunction is used to print the value ofi=++i == 6. - The expression
++iincrements the value ofiby 1 before it is used in the comparison. - The comparison
i == 6checks if the incremented value ofiis equal to 6. - The result of the comparison is assigned to
i. - The
printffunction prints the value ofi, which is the result of the comparison.
Now, let's analyze the expression i=++i == 6:
- The variable
iis incremented by 1, so its new value is 6. - The comparison
6 == 6evaluates to true, which is represented by the value 1. - The value 1 is assigned to
i.
Therefore, the value of i is 1.
The correct answer is B) 1.