All Exams Test series for 1 year @ ₹349 only
Question

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?

This question was previously asked in
UGC NET 2024 Management Question Paper (02-Sep-2024) (Shift 2)
The correct answer is

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.

Was this answer helpful?
Need Expert Advice?
Upcoming Exams
CTET
December 12, 2026
Test Series
UGC NET img
Teaching
UGC NET (Paper 2) 2026 Mock Test Series
796 Tests 2 Tests Free
4.4(39)
English
More Questions from UGC NET

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App