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?
public static void Main(string[] args)
{
int a = 4;
int c = 2;
bool b = (a % c == 0 ? true : false);
Console.WriteLine(b.ToString());
if (a/c == 2)
{
Console.WriteLine(“true”);
}
else
{
Console.WriteLine(“false”);
}
Console.ReadLine();
}

What will be the output of the following C# code?
public static void Main(string[] args)
{
int a = 4;
int c = 2;
bool b = (a % c == 0 ? true : false);
Console.WriteLine(b.ToString());
if (a/c == 2)
{
Console.WriteLine(“true”);
}
else
{
Console.WriteLine(“false”);
}
Console.ReadLine();
}
a) True
False
b) False
True
c) True
True
d) False
False

Answer: c
Explanation: a % c == 0 condition is true as (4 % 2 == 0). So, b is evaluated as true. Now (a/c == 2) which means if condition is also true hence it is evaluated as true.

Join The Discussion