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 = 2, k = 3;
switch (i – k)
{
case -1:
++i;
++k;
break;
case 2:
–i;
++k;
break;
default:
i += 3;
k += i;
break;
}
Console.WriteLine(i + “\n” + k);
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int i = 2, k = 3;
switch (i – k)
{
case -1:
++i;
++k;
break;
case 2:
–i;
++k;
break;
default:
i += 3;
k += i;
break;
}
Console.WriteLine(i + “\n” + k);
Console.ReadLine();
}
a) 2 3 3
b) 3 2 3
c) 3 4 4
d) 5 10 10

Answer: c
Explanation: i – k = -1. So, case -1 will be executed only.
Output: 3
4
4

Join The Discussion