What is the effect of dynamically allocating 100 bytes for an int*, and then trying to set values to it using pointer arithmetic?
<p>On a test I got back recently it had a question to the effect of, "assuming this code compiles, what will it do?"</p>

<p>Code:</p>

<pre><code>int *ptr

ptr = (int *) malloc( 25 * sizeof(int)); //100 bytes

*ptr = 'x';
*(ptr + 1) = 'x';
.... //go through all the values from 1 to 99 as well
*(ptr +99) = 'x';
</code></pre>

<p>I have written the code and run it and the result, when printed with <code>printf(%d, *x)</code> is 120, the ascii value of x. I understand that the int must just be being set to x, and when that is printed as an int the ascii value is printed, but I am stumped when it comes to what the actual effect of the malloc is, and what all of the <code>*(ptr + i)</code> actually does.</p>