Strange error in variable values C++
<p>I have used this code. Here a string is present from location starting from 4 and length of string is 14. All these calculations are done prior to this code. I am pasting a small snippet of the error containing code.</p>

<pre><code>void *data = malloc(4096);
int len = 14;
int fileptr = 4;
string str;
cout&lt;&lt;len&lt;&lt;endl;
cout&lt;&lt;fileptr&lt;&lt;endl;
memcpy(&amp;str, (char *)data+fileptr, len);        
cout&lt;&lt;len&lt;&lt;endl;
cout&lt;&lt;fileptr&lt;&lt;endl;
</code></pre>

<p>Output i get is:</p>

<pre><code>14
4
4012176
2009288233
</code></pre>

<p>Here i am reading a string "System Catalog" from memory. Its displaying the string correctly. But the values of fileptr and len are abruptly changing after using memcpy() function.</p>
