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 y = 3;
y++;
if (y <= 5)
{
Console.WriteLine(“hi”);
Main(args);
}
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int y = 3;
y++;
if (y <= 5)
{
Console.WriteLine(“hi”);
Main(args);
}
Console.ReadLine();
}
a) hi hi
b) hi
c) Stack overflow exception
d) None of the mentioned

Answer: c
Explanation: If loop never gets over, it will execute continuously. The control never goes out of ‘if’ statement.
Output: hi
hi
.
.
.
stack overflow exception

Join The Discussion