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?
class Program
{
static void Main(string[] args)
{
int i = 5;
int j;
method1(ref i);
method2(out j);
Console.writeline(i + ” ” + j);
}
static void method1(ref int x)
{
x = x + x;
}
static void method2(out int x)
{
x = 6;
x = x * x;
}
}

What will be the output of the following C# code?
class Program
{
static void Main(string[] args)
{
int i = 5;
int j;
method1(ref i);
method2(out j);
Console.writeline(i + ” ” + j);
}
static void method1(ref int x)
{
x = x + x;
}
static void method2(out int x)
{
x = 6;
x = x * x;
}
}
a) 36, 10
b) 10, 36
c) 0, 0
d) 36, 0

Answer: b
Explanation: Variable ‘i’ is passed as reference parameter declared with ‘ref’ modifier and variable ‘j’ is passed as a output parameter declared with ‘out’ keyword. Reference parameter used to pass value by reference is the same with out parameter.
Output :
10, 36

Join The Discussion