Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
static void Main(string[] args)
{
double a = 345.09;
byte c = (byte) a;
Console.WriteLine(c);
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
double a = 345.09;
byte c = (byte) a;
Console.WriteLine(c);
Console.ReadLine();
}
a) 98
b) 89
c) 88
d) 84

Answer: b
Explanation: Type casting a larger variable into a smaller variable results in modules of larger variable by range of smaller variable. a is ‘345.09’ which is larger than byte range ie -128 to 127.
Output :
89

Join The Discussion