TEZPUR 2025 Computer PYQ — What will be the value of after executing the following statement… | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
TEZPUR 2025 — Computer PYQ
TEZPUR | Computer | 2025
What will be the value of x after executing the following statements?
x = 8; y = 5;
x = x + y;
y = x - y;
x = x - y;
Choose the correct answer:
A.
13
B.
3
C.
5
(Correct Answer)
D.
8
Correct Answer:
5
Explanation
This sequence of statements is a classic algorithm used to swap the values of two variables without using a third temporary variable. Here is the step-by-step breakdown:
Initial State:
x=8
y=5
First Statement (x = x + y):
x=8+5
x=13
(Now, x holds the sum of both values, and y remains 5)
Second Statement (y = x - y):
y=13−5
y=8
(Now, y has been assigned the original value of x)
Third Statement (x = x - y):
x=13−8
x=5
(Finally, x is assigned the original value of y)
Conclusion: After executing these statements, the value of x becomes 5.
The correct option is (c).
Explanation
This sequence of statements is a classic algorithm used to swap the values of two variables without using a third temporary variable. Here is the step-by-step breakdown:
Initial State:
x=8
y=5
First Statement (x = x + y):
x=8+5
x=13
(Now, x holds the sum of both values, and y remains 5)
Second Statement (y = x - y):
y=13−5
y=8
(Now, y has been assigned the original value of x)
Third Statement (x = x - y):
x=13−8
x=5
(Finally, x is assigned the original value of y)
Conclusion: After executing these statements, the value of x becomes 5.