Multiple choice

Given code is written in C language. Find the output of the program.

int i = 6, j = 14, k = 7, l = 7, x; x = i > j ? j > k ? 12 : k > l? 13 : 14 : 15;printf("%d", x);

  1. 12

  2. 13

  3. 14

  4. 15

  5. %d

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

x = i > j ? j > k ? 12 : k > l? 13 : 14 : 15; Taking operator precedence, control will start executing from center of the statement. Step I:x = i > j ?( j > k ? 12 : k) > l? 13 : 14 : 15 // Control will get k from here  Step II: Remove the executed part for better understanding x = i > j ? ( k > l? 13 : 14) : 15  // Here value is 14 Step III: x = i > j ? 14 : 15 // i is not greater than j. Hence, 15 will be assigned in int x variable.