Computer Science, asked by rajita, 1 year ago

what will be the output(step by step) for the following-
if t=10.
1) t-=++t+(--t)*2
2)t+=t-- + ++t+ --t
ans for each case



kvnmurty: can you please rate the answer and i hope the step by step answer is clear.

Answers

Answered by kvnmurty
2
for 1)    t = - 18 after the statement is executed
               --t is done first.  so t becomes 9. u get 18 to right of +.  ++t gives 10. and on left of  + we have 10.  RHS of -= we have 28. t is now 10. 

  for 2)  t = 38    after the statement is executed
         --t is done first. so t=9. RHS =9.  ++t is 10 and t become 10. RHS is now 19. t-- gives 10 value and t becomes now 9.  RHS of += 29. 



kvnmurty: Write t -= (++t ) + (--t) * 2 . In this first --t will be done. t =9. E1=9. Then multiplication of E1 by 2. So E1 = 18. Then ++t will be done. So t = 10. E2 = 10. Then results E1 and E2 are added. So we get t -= 28. As t is 10 at this point, this will result in -18.
kvnmurty: write t += (t--) + (++t) + (--t) In this first --t is done. So t is 9. yu get E1 = 9. next ++t is done. so t becomes 10. E2 = 10. Now t-- is done. so t = 9. But E3 = 10 and not 9 as post-fix operator is used. Now add E1, E2, E3 to get 29. It becomes now t += 29 As t =9 at this point of time, t will become 38.
jayitasahatiya: t+=t dosnt mean t= ++t !!
kvnmurty: t += x means that t = old value of t + value of expression x
kvnmurty: If we dont understand the values, try a program online and see result
Answered by rajn58
0

Answer:

10,29 are answer friends

Similar questions