+ 1
Can you explain the output of this code?
2 Respostas
+ 5
Lets suppose a = 2 b = 4
b = a + b - ( a = b);
a = 2
b = 4
So first parenthesis
b = a + b - ( 4)
a = 2
b = 4
The value of 'a' will change because of ( a =b) after finishing the operation.
now a+ b
b = 2 + 4 - 4
b = 6 - 4
a = 2
b = 4
Finishing
b = 2
a = 4 // remenber ( a = b) effect occurs here
b =2
+ 1
consider the following user input
a=5 and b=6
first the value will be substituted in the expression b=a+b-(a=b):
b=5+6-(a=6)//here variable a now holds 6 because of assignment operation
Now for b
b=5+6-6=5//here variable b holds the value 5