title: c++ long to char array (8 byte) to long
body: <p>How can i change a <code>long</code> into a <code>char</code> array with 8 Byte and
  how can i change a <code>char</code> array with 8 Byte into <code>long</code> ?</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main () {
      long num=33;
      char* z;
      z = new char[8];
      z =  reinterpret_cast&lt;char *&gt;(&amp;num); // long to char array
      long r;
      r = reinterpret_cast&lt;long&gt;(&amp;z); // char array to long
      cout &lt;&lt; r &lt;&lt; &quot;\n&quot;;  // why is the output not 33
      printf(&quot;%x &quot;, z[0]); //print the 8 Byte char array
      printf(&quot;%x &quot;, z[1]);
      printf(&quot;%x &quot;, z[2]);
      printf(&quot;%x &quot;, z[3]);
      printf(&quot;%x &quot;, z[4]);
      printf(&quot;%x &quot;, z[5]);
      printf(&quot;%x &quot;, z[6]);
      printf(&quot;%x &quot;, z[7]);
      return 0;
  }
  </code></pre>
  <p>Why is the output <code>r</code> not 33?</p>