What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 10 , b = 20;
Console.WriteLine("Result before swap is: "+ a +" "+b);
swap(ref a, ref b);
Console.ReadLine();
}
static void swap(ref int i, ref int j)
{
int t;
t = i;
i = j;
j = t;
Console.WriteLine("Result after swap is:"+ i +" "+j);
}
static void Main(string[] args)
{
int a = 10 , b = 20;
Console.WriteLine("Result before swap is: "+ a +" "+b);
swap(ref a, ref b);
Console.ReadLine();
}
static void swap(ref int i, ref int j)
{
int t;
t = i;
i = j;
j = t;
Console.WriteLine("Result after swap is:"+ i +" "+j);
}A. Result before swap is: 20 10
Result after swap is: 20 10
B. Result before swap is: 10 20
Result after swap is:20 10
C. Result before swap is: 10 20
Result after swap is:10 20
D. Result before swap is: 20 10
Result after swap is:10 20
Answer: Option B

Join The Discussion