0

# int x=1; x=x+2*x++; printf ("%d",x); Output is 4 int x=1; x=x++; printf ("%d",x); output is 1

Anyone explain me why there is no increment in 2nd program while it is incrementing in 1st one

7/10/2019 2:20:00 PM

Rohit Ahuja

0

I think what it is doing is that , in the first code Initially x is 1 Then when it comes to second line for assigning to LHS it must first compute RHS soo here it sees there is an post increment in the statement soo it says "first use then increment" so it multiplies the value of 2 to 1 and then as x has been updated after this use it makes x to 2 soo now the concept is . X=2+2*1 . In the second code x in LHS is given value of 1 and not 2 since its post increment. And hence 1 is printed . The concept is about incrementation and usage , hope this helps.

0

Saket how u r solving the code 1st I am also trying to solve that but in youtube video one person explain that x=1+2*1=3 and then in the next line it print 4 by incr....

0

Brother I told you what I have experienced and learnt.I could have mistaken in understanding ,but I need a proper,more logical explanation to agree with you.

0

Ok bro don't worry just chill

0

If you can share that video ,it will be helpful..thankyou!