title: What is unsafe in this code?
body: <p>I am learning about managed and unmanaged code in CLR.
  So I wrote this example with C-style pointers in C#:</p>
  
  <pre><code>unsafe  static void Main(string[] args)
  {
      int x;
      int* y;
      y = &amp;x;
      *y = 50;
      Console.WriteLine(*y);
      Console.WriteLine(((int)y).ToString());
  }
  </code></pre>
  
  <p>So I am wondering what really is unsafe in IL code that I got from the code above?</p>
  
  <pre><code>.assembly extern mscorlib
  {}
  .assembly UnsafePointers
  {}
  .module UnsafePointers.exe
  .class private auto ansi beforefieldinit UnsafePointers.Program
  extends [mscorlib]System.Object
  {
      .method private hidebysig static void  Main(string[] args) cil managed
      {
          .entrypoint
          // Code size       34 (0x22)
          .locals init (int32 x,
          int32* y)
          IL_0001:  ldloca     x
          IL_0003:  conv.u
          IL_0004:  stloc      y
          IL_0005:  ldloc  y 
          IL_0006:  ldc.i4   50
          IL_0008:  stind.i4
          IL_0009:  ldloc      y
          IL_000a:  ldind.i4
          IL_000b:  call       void [mscorlib]System.Console::WriteLine(int32)
          IL_0010:  nop
          IL_0011:  ldloca     y
          IL_0012:  conv.i4
          IL_0016:  call       instance string [mscorlib]System.Int32::ToString()
          IL_001b:  call       void [mscorlib]System.Console::WriteLine(string)
          IL_0021:  ret
      } 
  }    
  </code></pre>
  
  <p>Does CLR manages this code?  And what can go wrong with a code above?</p>