What is the out put of the following codebyte a=200;byte b=100;byte c=a+b;Response.Write ( C );

Skill/Topic: Advanced
A) 300
B) Compile Time error
C) Run time Error
D) Just prints “C”

Showing Answers 1 - 9 of 9 Answers

samiksc

  • Aug 3rd, 2007
 

The correct answer is B compile time error.
The reason is byte + byte results into int value, which cannot be implicitly typecasted to byte. You need to carry out an explicit cast in one of the following ways:
1. c = (byte)(a+b); : In this case the output displayed is 44 (note that byte ranges from 0 to 255.)
2. c = Convert.ToByte(a+b); : In this case the output is runtime error for OverflowException.

  Was this answer useful?  Yes

Mounika

  • Jul 10th, 2023
 

compile time error

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions