Consider the following statements int x = 10, y = 15; x = ((x = y) ? (y + x) : (y - x)); What will be the value of x after executing these statements?
30
In C, = is assignment and == is comparison. An assignment expression has the value assigned, and the conditional operator c ? e1 : e2 treats any non-zero value of c as true. There is a sequence point after the first operand of ?:, so the side effect of the condition is complete before the chosen branch is evaluated.
Step 1 — Initially x = 10 and y = 15.
Step 2 — The condition (x = y) assigns 15 to x; the expression's value is 15, which is non-zero, so the condition is true.
Step 3 — The true branch (y + x) is evaluated with the updated x: \(15 + 15 = 30\).
Step 4 — The outer assignment stores this value, so x becomes 30.
The value 5 would come from reading the condition as a comparison 10 == 15 (false) and taking y − x; 25 is y + x with the old x = 10; 15 is the value of x right after the inner assignment, before the outer one.
30 option is correct.