title: dynamic allocation of array of pointers
body: <p>The following code gives a segmentation fault. I am not able to figure out as to why. Please see..</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int **ptr;
      int *val;
      int x = 7;
      val = &amp;x;
      *ptr = (int *)malloc(10 * sizeof (*val));
      *ptr[0] = *val;
      printf("%d\n", *ptr[0] );
  
      return 0;
  }
  </code></pre>
  
  <p>on debugging with gdb, it says:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  
  0x0804843f in main () at temp.c:10
  
  *ptr = (int *)malloc(10 * sizeof (*val));
  </code></pre>
  
  <p>Any help regarding the matter is appreciated.</p>