- 1
a=9, b=9, a=b++;b=a++;b=++b; how to solve please give all possible out puts
All possible outputs
4 Answers
0
CHILUKAMARI VENKATESH
tricky problem... do's it come from a challenge?
result: a == 10 and b == 10
details:
a=9 : 9 in a => a == 9
b=9 : 9 in b => b == 9
a=b++ : b(9) in a, then b=b(9)+1=10 => a == 9, b == 10
b=a++: a(9) in b, then a=a(9)+1=10 => a == 10, b == 9
b=++b : b=b(9)+1=10 (++b), then b in b => a==10, b == 10
0
this is the only one output possible, in any languages wich have incrementation/decrementation operators, but that's a tricky case, as you will almost only encounter it in test questions ;)
0
But in our book they mentioned 4 out puts they are 9,9
10,10
10,9,
9,10
0
with js, but it must be the same in C:
https://code.sololearn.com/WXMW6uZ0pRoB/?ref=app