Question 6
Back to Exercise
What happens to two short values in a + b?
- A They are added as shorts and may wrap
- B Both are promoted to int, and the sum is an int Correct
- C They are converted to long
- D The sum is a short
Correct Answer: Option B
Integer promotion converts every type narrower than int to int before arithmetic. So short + short is computed in int and cannot overflow a short – but assigning the result back to a short may truncate it.
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!