 <p>Here:</p> <pre><code>struct integer* x= malloc(sizeof(int) * 100);; </code></pre> <p>you are allocating memory for the structure (i.e. the pointer and the int), but not for the array.</p> <p>The moment you try to assign to <code>x-&gt;arr[j]</code>, you have <a href="http://en.wikipedia.org/wiki/Undefined_behavior" rel="nofollow">undefined behaviour</a>.</p>