Prints i = 5. But its (4)+(5) = 9 right?Code:int main() { int i=3; int j; ++i + ++i; printf("\n\ti=%d j=%d", i ,j); //Prints i = 5. But its (4)+(5) = 9 right? return 0; }
Prints i = 5. But its (4)+(5) = 9 right?Code:int main() { int i=3; int j; ++i + ++i; printf("\n\ti=%d j=%d", i ,j); //Prints i = 5. But its (4)+(5) = 9 right? return 0; }
okay, I think, since their is no assignment operator. summing of ++i and ++i does not happen. Right ?
The only thing that is safe to say is that the expression "++i + ++i" is syntactically correct but semantically meaningless. It is not allowed to assume that the value of i is anything in particular, or that it even exists anymore. It is likely that since the expression was not assigned to j, the only thing that happened were the side effects (i was incremented twice, giving a value of 5), and no addition occurred.
What would be kind of cool is the ability to play a sound file of a guy with a good radio voice going, "Ladies and gentlemen..... Welcome to UNDEFINED BEHAVIOR!"
I think such a warning might be appropriate in this topic in the near future, if not right now.
thanks guys