Multiple choice

Give the output of the following program: main( ) { int a=30,b=40,x; x=((a!=10) && (b=50)) printf(“x=%d”,x)' }

  1. x = 1

  2. x = 0

  3. no output

  4. none of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The expression (a!=10) evaluates to 1 (true). Because of short-circuit evaluation in the AND operator, (b=50) is evaluated, which returns 50 (true). The result of 1 && 1 is 1.