What is the result of an assignment expression in C?

user2131316 picture user2131316 · May 15, 2013 · Viewed 8.8k times · Source

In the following code:

int c;
while((c=10)>0)

What does c = 10 evaluate to? Is it 1 which indicates that the value 10 is assigned to variable c successfully, or is it 10? Why?

Answer

Bathsheba picture Bathsheba · May 15, 2013

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