Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the value of the below assignment expression
      (x = foo()) in the statement (x = foo()) != 1, considering that foo() returns 2?

  • A.2
  • B.true
  • C.1

Answer: A

Correct answer: 2

The value of an assignment expression is the value assigned. foo() returns 2, so x becomes 2 and the expression (x = foo()) itself has the value 2. That value is then what the surrounding != 1 compares against - and the comparison, being a separate expression, would yield 1.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.