Why is an assignment an expression?

Why is an assignment an expression without giving any value ?

It does give a value: the value of the just assigned variable. E. g.

v = x = c;

is equivalent to

x = c;
v = x;

as the value of x = c is the value of x after the expression was evaluated.

2 Likes

The explanation is correct.
But you can not rely on the order of side effects in an expression.
Therefore, it might in general not be the case that a nested assignment behaves the same as a sequential one.
Especially, if more than one side effect are performed in an expression.

For instance with arr[arr[x]] = arr[x] = y or even simpler x=x++ (or x=y=y++ with nested assignments).

https://c-faq.com/expr/seqpoints.html

2 Likes