What is the behavior of the following piece of code? int i = 0; i++ + --i;
stays at 0, increment + decrement = same so i++ +i--; = 0.
post increment + pre decrement........... where did you find such a stuff........... its bad idea to use such operations......
that piece of code would need to be i++ + i--; or else it would return an error; would remain = 0
nope, --i is also a kind of operator like i++ is post increment whereas ++i is pre increment!
is this a homework assignment, agd?
Actually, its behavior is undefined ^^
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++
Another example of undefined behavior: i = i++;
Is while(*target++ = *source++) undefined behavior too?
I'll try in that other compiler.
it remains the same .........
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 ...
Join our real-time social learning platform and learn together with your friends!