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 a = 5;
int s = 0, c = 0;
Mul (a, ref s, ref c);
Console.WriteLine(s + “t ” +c);
Console.ReadLine();
}
static void Mul (int x, ref int ss, ref int cc)
{
ss = x * x;
cc = x * x * x;
}

What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 5;
int s = 0, c = 0;
Mul (a, ref s, ref c);
Console.WriteLine(s + “t ” +c);
Console.ReadLine();
}
static void Mul (int x, ref int ss, ref int cc)
{
ss = x * x;
cc = x * x * x;
}
a) 125 25
b) 25 125
c) Compile time error
d) 0 0

Answer: b
Explanation: The value of variable a is passed by value while value of variable s and c is passed by reference.
Output: 25 125

Join The Discussion