Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

explain output of int x = 4; x = x + x + x++; printf("%d\n",x); x = 4; printf("%d\n",x + x + x++); output of above code is 13 12

Computer Science
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
x++ means: first read the current value of x and then increment its value. so in the statement: x = x + x + x++ what happens is as follows: x = 4 + 4 + 4 = 12 then the "post increment" on x is applied (i.e. x++) resulting in x getting the value 13 In the second statement: printf("%d\n",x + x + x++); the same thing happens, except this time the result of "x + x + x++" is printed out first and then the current value of x is incremented - which in this case would mean x would end up with a value of 5.
it doesn't work on #define p(x) printf("%d\n",x); int x = 4; x = x + x++ + x; p(x); x = 4; p(x + x++ + x); same output 13 12
what do you mean by it doesn't work?

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

according to ur explanation first + is evaluated then increment but post increment has higher precedence than normal addition and assignment operator so it should be evaluated first
post increment always occurs AFTER the value has been read and processed
thanks i get it.
yw :)

Not the answer you are looking for?

Search for more explanations.

Ask your own question