2 votes 2 votes closed with the note: answered #include <stdio.h> int main(){ int a=1 , b=3; a += b -= a-=b; printf("%d %d",a,b); } what is the output ? a. 3 4 b. 3 5 c. 2 4 d. compilation fails Programming in C output + – nish kim asked Aug 31, 2017 closed Sep 1, 2017 by nish kim nish kim 6.1k views comment Share Follow See all 0 reply Please log in or register to add a comment.
3 votes 3 votes ans b) 3,5 expand the expression in this way for clarity : a=a+b=b=b-a=a=a-b; execute from right to left. 3= -2+5= 5 = 3 - (-2) = -2 = 1-3 note: this kind of expression has unspecified behavior for different compilers. I executed in gcc 5.3.0 Tuhin Dutta answered Sep 1, 2017 Tuhin Dutta comment Share Follow See 1 comment See all 1 1 comment reply nish kim commented Sep 1, 2017 reply Follow Share Thanks a lot. 1 votes 1 votes Please log in or register to add a comment.
3 votes 3 votes Answer is : (b) 3 5 a+=b-=a-=b; This contains three logics: a+=b; => a=a+b; b-=a; => b=b-a; a-=b; => a=a-b; in the main logic these three logics are equal: a=a+b = b=b-a = a=a-b; -2 =1-3 5=3-(-2) 3=-2+5 so, a=3,b=5 amrendra pal answered Sep 1, 2017 amrendra pal comment Share Follow See all 0 reply Please log in or register to add a comment.