title: C++ Unable to write to virtual memory despite being marked as read & write
body: <p>I am unable to write to a virtual memory block despite it being flagged as PAGE_READWRITE. This is the exception thrown at runtime:</p>
  
  <pre><code>Exception thrown at 0x722E4AE9 (vcruntime140d.dll) in ConsoleApplication.exe: 0xC0000005: Access violation writing location 0x00000000.
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  int main() {
      char* memblock;
  
      memblock = new char[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
  
      LPVOID virtual_memory_area = VirtualAlloc(NULL, 8, MEM_PHYSICAL, PAGE_READWRITE);
      memcpy(virtual_memory_area, memblock, 8);
  }
  </code></pre>