Find the output of this program. main() { int i=5; printf(ā€œ%dā€,i=++i ==6); }

  1. 6

  2. 1

  3. 5

  4. Compiler error


Correct Option: B

AI Explanation

To find the output of the given program, let's go through each step:

  1. The variable i is initialized with a value of 5.
  2. The printf function is used to print the value of i=++i == 6.
  3. The expression ++i increments the value of i by 1 before it is used in the comparison.
  4. The comparison i == 6 checks if the incremented value of i is equal to 6.
  5. The result of the comparison is assigned to i.
  6. The printf function prints the value of i, which is the result of the comparison.

Now, let's analyze the expression i=++i == 6:

  1. The variable i is incremented by 1, so its new value is 6.
  2. The comparison 6 == 6 evaluates to true, which is represented by the value 1.
  3. The value 1 is assigned to i.

Therefore, the value of i is 1.

The correct answer is B) 1.

Find more quizzes: