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 = 0, j = 0;
while (i < 2)
{
l1: i–;
while (j < 2)
{
Console.WriteLine(“hi\n”);
goto l1;
}
}
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int i = 0, j = 0;
while (i < 2)
{
l1: i–;
while (j < 2)
{
Console.WriteLine(“hi\n”);
goto l1;
}
}
Console.ReadLine();
}
a) hi hi hi
b) hi
c) Error
d) hi hi hi…..infinite times

Answer: d
Explanation: Since, i– so, test condition for ‘i’ never satisfies it fails and hence infinite loop in occurs.
Output: hi hi hi…..

Join The Discussion