Practice mode C Language

In the C statement a = b = c = 4;, why do all three variables receive the value 4?

Correct answer B. Assignment associates right to left, so c = 4 is evaluated first and its value is assigned onward

Explanation

Assignment operators group right to left, so the statement parses as a = (b = (c = 4)). An assignment expression has the value of the left operand after assignment, so c = 4 yields 4, which is then assigned to b and then to a. Left-to-right grouping would mean (a = b) = c, which is invalid because an assignment expression is not an lvalue in C.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.