title: I succeeded allocating a pointer to an array of 3 ints in the heap, but I still don't understand how does the access to the array work?
body: <p>After several trials I've succeeded allocating a pointer to an array of 3 <code>int</code>s with a <em>new expression</em>. In the snippet below, I show first the use of this pointer in the stack, and then I show where I've got with the heap allocation, after several trials.</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
      // First, pointer p to an array of 3 int's in the stack.
  
      int a[3] = { 10, 11, 12 };
      int(*p)[3] = &amp;a;
      std::cout &lt;&lt; **p &lt;&lt; "  " &lt;&lt; *(*p + 1) &lt;&lt; "  " &lt;&lt; *(*p + 2) &lt;&lt; '\n';
      std::cout &lt;&lt; p[0][0] &lt;&lt; "  " &lt;&lt; p[0][1] &lt;&lt; "  " &lt;&lt; p[0][2] &lt;&lt; '\n';
  
      // Second, the pointer is allocated on the heap.
  
      int(**q)[3] = new (int(*)[3]) {p};
  
      // That's what I've got after several trials. But I'm still trying to
      // understand how does the access to the array work in the next two lines of code?
  
      std::cout &lt;&lt; ***q &lt;&lt; "  " &lt;&lt; ***q + 1 &lt;&lt; "  " &lt;&lt; ***q + 2 &lt;&lt; '\n';
      std::cout &lt;&lt; q[0][0][0] &lt;&lt; "  " &lt;&lt; q[0][0][1] &lt;&lt; "  " &lt;&lt; q[0][0][2] &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>The code prints</p>
  
  <pre><code>10  11  12
  10  11  12
  10  11  12
  10  11  12
  </code></pre>
  
  <p>See <a href="http://coliru.stacked-crooked.com/a/d5fdfe88a17d9585" rel="nofollow">live example</a></p>
  
  <p><strong>Edit</strong> @A.S.H. found an error in my code, in his comment below. I'm making the necessary changes to clarify the example.</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
      // First, pointer p to an array of 3 int's in the stack.
  
      int a[3] = { 100, 200, 300 };
      int(*p)[3] = &amp;a;
      std::cout &lt;&lt; **p &lt;&lt; "  " &lt;&lt; *(*p + 1) &lt;&lt; "  " &lt;&lt; *(*p + 2) &lt;&lt; '\n';  // Change here
      std::cout &lt;&lt; p[0][0] &lt;&lt; "  " &lt;&lt; p[0][1] &lt;&lt; "  " &lt;&lt; p[0][2] &lt;&lt; '\n';
  
      // Second, the pointer is allocated on the heap.
  
      int(**q)[3] = new (int(*)[3]) {p};
      std::cout &lt;&lt; ***q &lt;&lt; "  " &lt;&lt; *(**q + 1) &lt;&lt; "  " &lt;&lt; *(**q + 2) &lt;&lt; '\n';  // Change here
      std::cout &lt;&lt; q[0][0][0] &lt;&lt; "  " &lt;&lt; q[0][0][1] &lt;&lt; "  " &lt;&lt; q[0][0][2] &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>With these changes the code is much clearer. If I knew about this error before, I wouldn't have placed the question. Thanks @A.S.H. for your input. </p>