Possible Duplicate:
Undefined Behavior and Sequence Points
What is the outcome of the following code:
#include <stdio.h>
int main() {
int a = 3;
a= (a = 2) + (a = 3);
printf("%d", a);
}
Why do I get 6 as the output on gcc? Why not 5?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re both writing and reading variable
abetween sequence points, so the result is formally undefined behavior.Looking at the assembly code generated by your particular compiler will make it clear why you get a particular result, but the standard makes no guarantees at all.