Im new to pointers (just began learning) and came across the following code snippet and needed to predict the output. My answer was 220 but was told its wrong. Could someone tell me the correct output and please explain why.
using System;
class pointer
{
public static void Main()
{
int ptr1=0;
int* ptr2=&ptr1;
*ptr2=220;
Console.WriteLine(ptr1);
}
}
EDIT: Thank you everybody for the explanatory answers. The correct answer is definitely 220 if and only if the above block of code (which is C# code, Sorry for not mentioning it in the question) was declared as unmanaged. Thank you for all your answers. Every one of em was really informative and helpful.