Write data to memory in c++
<p>I had posted a question on this but I thought to use memcmp() function instead.
<a href="http://stackoverflow.com/questions/7790751/writing-data-to-memory-in-c/7790785#comment9505045_7790785">Writing data to memory in C++</a></p>

<pre><code>int x = 1;
int fileptr = 0;
void *data = malloc(4096);
memcpy((int *)data+fileptr, &amp;x, sizeof(int));
</code></pre>

<p>Then I read the values back</p>

<pre><code>int y;
fileptr = 0;
memcpy(&amp;y, (int *)data+fileptr, sizeof(int));
cout&lt;&lt;y;
</code></pre>

<p>In this way, I get a different output for variable y (some long integer values). Please need immediate help.</p>
