What is the output of the following pseudocode ?
x = 5
y = x++
z = ++x
print(x + y + z)
Tripura Public Service Commission - 2026,
Answer: B
The output is 19.
Trace the variables line by line:
x = 5, so x is 5.y = x++is post-increment: y takes the old value 5, then x becomes 6.z = ++xis pre-increment: x becomes 7 first, then z takes 7.x + y + z= 7 + 5 + 7 = 19.
18 comes from forgetting the final increment and using x = 6 (6 + 5 + 7). 20 and 21 come from treating x++ as if it also gave the new value to y.
Please log in or register to report this question.