Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the following conditional expression

z = (x \gt y) ? x : y;

if x = 2 and y = 8, the value of z is

  • A.2
  • B.8
  • C.6
  • D.10

Answer: B

The value of z is 8, the second option. The conditional expression returns x if the condition (x > y) is true and y otherwise. With x = 2 and y = 8 the condition \(2 \gt 8\) is false, so z takes the value of y, which is 8.

The value 2 would be the result if the condition were true, and 6 and 10 are the difference and the sum of the two numbers, which the expression does not calculate.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.