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 = 5;
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 = 5;
for (; Convert.ToBoolean(Convert.ToInt32(i)); Console.WriteLine(i–)) ;
Console.ReadLine();
}
a) 4 3 2 1
b) 3 2 1
c) 5 4 3 2 1
d) 2 1

Answer: c
Explanation: Since, i = 5 and test condition is executed until i!=0. So, i– decrements value of i till condition is satisfied.
Output: 5 4 3 2 1

Join The Discussion