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 i = -10;
for ( ;Convert.ToBoolean(Convert.ToInt32(i)) ;Console.WriteLine(i++)) ;
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int i = -10;
for ( ;Convert.ToBoolean(Convert.ToInt32(i)) ;Console.WriteLine(i++)) ;
Console.ReadLine();
}
a) -9 -8 -7 -6 -5 -4 -3 -2 -1
b) -10 -9 -8 -7 -6 -5 -4 -3 -2
c) -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
d) -8 -7 -6 -5 -4 -3 -2 -1

Answer: c
Explanation: For first value of i = -10. Condition is executed until i!=0.
Output: -10 -9 -8 -7 -6 -5 -4 -3 -2 -1

Join The Discussion