What will be the output of the following C# code snippet?
unsafe static void Main()
{
int a = 5;
int b = 5;
int c = 5;
int*[] ptr = new int* [3];
ptr[0] = &a;
ptr[1] = &b;
ptr[2] = &c;
for (a = 0; a < 3; a++)
{
c += *ptr[a];
Console.WriteLine(c);
}
Console.ReadLine();
}
unsafe static void Main()
{
int a = 5;
int b = 5;
int c = 5;
int*[] ptr = new int* [3];
ptr[0] = &a;
ptr[1] = &b;
ptr[2] = &c;
for (a = 0; a < 3; a++)
{
c += *ptr[a];
Console.WriteLine(c);
}
Console.ReadLine();
}
A. 5 10
B. 10 20
C. Compile time error
D. 5 10 20
Answer: Option D
Join The Discussion