What is the result after execution of the following code if ‘a’ is 10, ‘b’ is…
2022
What is the result after execution of the following code if ‘a’ is 10, ‘b’ is 5 and ‘c’ is 10? if ((a>b)&&(a<c)) a = a + 1; else c = c + 1;
- A.
a = 10, c = 10
- B.
a = 11, c = 10
- C.
a = 10, c = 11
- D.
a = 11, c = 11
Attempted by 505 students.
Show answer & explanation
Correct answer: C
The correct option is Option 3: a = 10, c = 11.
The code uses the logical AND operator &&. For the if block to execute, both conditions must be true.
Condition 1:
(a > b)→10 > 5is True.Condition 2:
(a < c)→10 < 10is False.
Since one condition is false, the else block executes, incrementing c while a remains unchanged.