Difficulty: Easy
Correct Answer: A value 8000 will be assigned to a.
Explanation:
Introduction / Context:
This checks your understanding of integral promotion and arithmetic in C#. Even though operands are shorts, arithmetic is performed using int unless explicitly controlled.
Given Data / Assumptions:
Concept / Approach:
In C#, short and byte are promoted to int for arithmetic. Thus s1 * s2 is computed as int * int → int, producing 8000. No overflow occurs because 8000 is well within int range.
Step-by-Step Solution:
Verification / Alternative check:
Change a to short and assign a = (short)(s1 * s2). Then a remains 8000 because 8000 fits in short as well; no overflow in either case here.
Why Other Options Are Wrong:
No wraparound or negative result occurs; there is no widening error; and “overflow due to Short” is irrelevant because the computation is done in int.
Common Pitfalls:
Assuming that arithmetic stays in the smaller operand type or that promotions cause overflow automatically.
Final Answer:
A value 8000 will be assigned to a.
Discussion & Comments