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);
}
The result of an assignment is the value. Therefore the expression evaluates to 4 or a non-zero and thus, in C, TRUE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With