Why does the following code run the while loop? I thought “mid = term” is an assignment, not a condition? Please explain. Thanks.
#include <stdio.h>
main ()
{
int mid = 4, term = 4;
while ( mid = term)
printf("%d\n", --term);
}
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.
The result of an assignment is the value. Therefore the expression evaluates to
4or a non-zero and thus, in C,TRUE.