Question 2
Back to Exercise
What does if (x = 5) { … } do?
- A Compares x with 5
- B Assigns 5 to x, and the body always runs because 5 is non-zero Correct
- C It does not compile
- D Assigns 5 only if x was 0
Correct Answer: Option B
= is assignment; its value is the value assigned (5), which is true. Compilers warn ("using the result of an assignment as a condition"). Use == to compare.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!