C# Programming - Datatypes - Discussion

Discussion Forum : Datatypes - General Questions (Q.No. 9)
9.

Which of the following statements is correct about the C#.NET code snippet given below?

short s1 = 20;
short s2 = 400;
int a;
a = s1 * s2;
A value 8000 will be assigned to a.
A negative value will be assigned to a.
During arithmetic if the result exceeds the high or low value of the range the value wraps around till the other side of the range.
An error is reported as widening conversion cannot takes place.
An overflow error will be reported since the result of the multiplication exceeds the range of a Short Integer.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Toetian said:   4 years ago
No error a = 160000.

But if you used a bigger number you will get error such as.

Constant value 'value' cannot be converted to a 'type'.

Raj said:   1 decade ago
If the value of s1=400 and s2=400 then what will happen.

VISHWANATH said:   1 decade ago
As the value 8000 is in the limits of short integer we can easily get that.

But if ever the situation is such that the value exceeds the limit of the data type taken then that goes to wrap from the other extreme.

Aarthi said:   1 decade ago
s1 = 20
s2 = 400
int a
a = s1*s2
a=20*400
a=8000
Value of a is 8000

Post your comments here:

Your comments will be displayed after verification.