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)
{
int x = 10;
do
{
Console.WriteLine( x++);
}
while(Convert.ToBoolean(5) && Convert.ToBoolean(4) && Convert.ToBoolean(3) && Convert.ToBoolean(2) && Convert.ToBoolean(1) && Convert.ToBoolean(0));
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int x = 10;
do
{
Console.WriteLine( x++);
}
while(Convert.ToBoolean(5) && Convert.ToBoolean(4) && Convert.ToBoolean(3) && Convert.ToBoolean(2) && Convert.ToBoolean(1) && Convert.ToBoolean(0));
Console.ReadLine();
}
a) 13
b) 15
c) 11
d) 10

Answer: d
Explanation: Here in do while condition ‘&&’ i.e ‘AND’operator return ‘0’ i.e false. So, as condition is false so program comes out of the loop.
Output : 10.

Join The Discussion