Dark Mode

239 views

0 votes

**Answer: C, D**

int a = 1, b = 0

__Option A:__ b++ && b == a

First b && b == a will be evaluated then b++ will be done, since b is 0 i.e. false and false && anything evaluates to false.

__Option B__: b++ && a==0, same as explained above this expression will also evaluates to false.

__Option C__: a || b == --a, since a is true and true || anything is true so this expression evaluates to true.

__Option D:__ a || ++b == 0, here also a is 1 and true || anything is true so this expression will also evaluates to true.

0

@Godlike Yes grouping will be according to the precedence like $a ||b==--a$ will be equivalent to $(a || (b==(--a)))$ but don’t confuse precedence over order of execution. Logical operators guarantees that the execution will be from left to right.

Since a = 1 so it will evaluates to true and due to the presence of || it will short-circuit and the expression will return true. Right side of the || will never get executed.

0

0 votes

$b++$ is postfix increment operator. The old value of b will be used (and then b will be incremented by 1).

$b++ = 0$ which is false when used in logical operation. False && anything is false.

Hence, both option A and B are false.

$a = 1$ which is true when used in logical operation. True || anything is true.

Hence, both C and D are true.

$b++ = 0$ which is false when used in logical operation. False && anything is false.

Hence, both option A and B are false.

$a = 1$ which is true when used in logical operation. True || anything is true.

Hence, both C and D are true.