What is the result of an assignment expression in C? [duplicate] What is the result of an assignment expression in C? [duplicate] c c

What is the result of an assignment expression in C? [duplicate]


c = 10 is an expression returning 10 which also assigns 10 to c.


It is said in C99 6.5.16

An assignment operator stores a value in the object designated by the left operand. An        assignment expression has the value of the left operand after the assignment, but is not an lvalue.


Assignment returns with the assigned value. In case c=10 is 10. Since 10!=0, in c it means also true so this is an infinite loop.

It is like you would write

while(10)

Plus You've made the assignment.

If You follow this logic, You can see, that

while(c=0)

would be a loop that never executes its statement or block.