Question regarding ++ in c | SoloLearn: Learn to code for FREE!


Question regarding ++ in c

I know that in standard C the output of this program is undefined. because : If you modify a variable more than one time in a single statement the behavior is undefined according to the C standard. But I dont know how the output here is 8:

10/27/2018 2:32:47 PM


2 Answers

New Answer


x = 3 x++ // will be incremented after this x is used, so it stays 3 + // addition ++x // will increment x before its used. x is now 4, because of above, and 4 + 1 = 5, so x is 5 3 + 5 = 8


If i remember correctly this is not more the standard. The operators used in code have preference well been defined, so you cannot have a double interpretation that causes undefined behavior. Probably this was the standard in first's compilers versions of C language,