title: Process finished with exit code 11 | Error during malloc
body: <p>Trying to understand memory allocation in C. Facing issue while trying to create two arrays using pointer to integers. Kindly have a look at the below code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
  
      int *a;
      int *b;
  
      for (int i = 0; i&lt;4;i++)
      {
          printf("Enter value \n");
          a[i]=(int *)malloc(sizeof(int));
          b[i]=(int *)malloc(sizeof(int));
          scanf("%d",&amp;a[i]);
          scanf("%d",&amp;b[i]);
      }
      for (int i =0;i&lt;4;i++)
      {
        printf("%d = %x\n  ",a[i],&amp;a[i]);
  
      }
      for (int i =0;i&lt;4;i++)
      {
       printf("%d = %x\n  ",b[i],&amp;b[i]);
  
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I am working with C11 on CLion. Facing below error on runtime. Can someone please explain what is wrong with this code ?</p>
  
  <pre><code>Enter value 
  
  Process finished with exit code 11
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FnHJ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FnHJ2.png" alt="b is being shown as NULL during debugging"></a></p>
  
  <p>"b is being shown NULL during debugging"</p>
  
  <p>UPDATE:
  Tried on another IDE, where "a" itself is not being allocated any memory. It directly gives me segmentation fault.</p>
  
  <p>UPDATE 2:
  Changing: </p>
  
  <pre><code>int *a;
  int *b;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>int *a = NULL;
  int *b = NULL;
  </code></pre>
  
  <p>at least stops how this code is behaving. It gives me segmentation fault as soon as I try to allocate memory to a[i] (Which is wrong, now I get).</p>