Looking at the code:
int i = 5;
if (i = 0)
{
printf ("Got here\n");
}
What does the C standard have to say about what will get printed?
Or in more general terms does the assignment happen first or the comparison?
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.
§6.8.4 says that the syntax for an
ifselection statement is:Further in this section, it mentions that if the expression compares unequal to 0, then
statementis executed. The expression must therefore be evaluated before it can be compared to 0.i = 0is an expression which evaluates to 0. For further reference, see §6.5 “Expressions” with regards to §6.5.16 “Assignment operators”, in particular note this excerpt: