Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

What is the behavior of the following piece of code? int i = 0; i++ + --i;

OpenStudy (anonymous):

stays at 0, increment + decrement = same so i++ +i--; = 0.

OpenStudy (anonymous):

post increment + pre decrement........... where did you find such a stuff........... its bad idea to use such operations......

OpenStudy (anonymous):

that piece of code would need to be i++ + i--; or else it would return an error; would remain = 0

OpenStudy (anonymous):

nope, --i is also a kind of operator like i++ is post increment whereas ++i is pre increment!

OpenStudy (anonymous):

is this a homework assignment, agd?

OpenStudy (anonymous):

Actually, its behavior is undefined ^^

OpenStudy (anonymous):

well, using gcc, the expression evaluates to -2, while the value of i becomes 0. I think it's due to --i happening first, then both -1s being added, then i++

OpenStudy (anonymous):

Another example of undefined behavior: i = i++;

OpenStudy (anonymous):

Is while(*target++ = *source++) undefined behavior too?

OpenStudy (anonymous):

I'll try in that other compiler.

OpenStudy (anonymous):

it remains the same .........

OpenStudy (anonymous):

int i = 0; i++ + --i; compiler gets confused if any can fix this I'll be surprised the --i is to be done to i or i++ basically that's its confusion ...

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!