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;

  1. A.

    a = 10, c = 10

  2. B.

    a = 11, c = 10

  3. C.

    a = 10, c = 11

  4. 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.

  1. Condition 1: (a > b)10 > 5 is True.

  2. Condition 2: (a < c)10 < 10 is False.

Since one condition is false, the else block executes, incrementing c while a remains unchanged.

Explore the full course: Up Lt Grade Assistant Teacher 2025