title: Casting pointer to Array (int* to int[2])
body: <p>How do I cast or convert an int* into an int[x]?</p>
  <p>First, I know that pointers can be indexed. So I know that I can <strong>loop through the pointer</strong> and array and manually convert the pointer. (eg. a for loop with <code>arr[i] = p[i]</code>). I want to know if the same result can be achieved in fewer lines of code.</p>
  <p>As an example I tried to cast pointer <code>int* c = new int[x]</code> to an array <code>int b[2]</code></p>
  <pre><code>int a    = 1;
  int b[2] = { 2, 3 };
  int* c   = new int[b[1]];
  
  c[0] = b[0];
  c[1] = b[1];
  c[2] = a;
  </code></pre>
  <p>I wanted to see what values were where, so I made a simple program to output addresses and values. The output is just below:</p>
  <pre><code>Address of {type: int}    &amp;a    =       0031FEF4; a    = 1
  Address of {type: int[2]} &amp;b    =       0031FEE4; b    = 0031FEE4
  Address of {type: int[2]} &amp;b[0] =       0031FEE4; b[0] = 2
  Address of {type: int[2]} &amp;b[1] =       0031FEE8; b[1] = 3
  Address of {type: int*}   &amp;c    =       0031FED8; c    = 008428C8
  Address of {type: int*}   &amp;c[0] =       008428C8; c[0] = 2
  Address of {type: int*}   &amp;c[2] =       008428D0; c[2] = 1
  </code></pre>
  <p>Once I made sure I knew what was where I tried a few things. The first idea that came to mind was to get the address of the second element to the pointer's allocation, then replace the array's memory address with it (see the code just below). Everything I did try ultimately failed, usually with syntax errors.</p>
  <p><strong>This is what I tried.</strong> I really want this to work, since it would be the simplest solution.</p>
  <pre><code>b = &amp;c[1];
  </code></pre>
  <p>This did not work obviously.</p>
  <p><strong>Edit: Solution:</strong>
  <em>Don't do it!</em>
  If it's <strong>necessary</strong> create a pointer to an array and then point to the array; this is pointless for any purposes I can fathom.
  For more detailed information see the answer by rodrigo below.</p>