Expression and statement confusion

Hi,everyone. I am confused with the questions below. Can someone help me?
Which of these statements are true?

(a) Any expression can be used as a statement in C++.

(b) The expression x++ can be used as a statement.

(c) The statement x = x + 5 is also an expression.

(d) The statement x = y = x = 0 is illegal.


> (a) Any expression can be used as a statement in C++.

Yes, as an expression statement with a semicolon at its end; (the expression is a discarded value expression).

> (b) The expression x++ can be used as a statement.
> (c) The statement x = x + 5 is also an expression.

x++ is an expression and x++; is a statement (an expression statement, note the semicolon).
x = x + 5; appearing by itself is a full statement terminated by a semicolon, it is not an expression.
x = x + 5 is an expression

> (d) The statement x = y = x = 0 is illegal.

To make it a syntactically valid statement, add a semicolon at the end x = y = x = 0;

Note:
If x is an object of a scalar type, evaluating x = y = x = 0 engenders undefined behaviour prior to C++17.
wow, thank you verr much!!!!!!!!!!
Registered users can post here. Sign in or register to post.