title: 2d array using a double pointer and malloc function
body: <p>i am trying to create a 2d array using  double pointer...
  my code is...<hr/></p>
  
  <pre><code>int **p1;
  p1=(int **) malloc(2*sizeof(int *));
  for(int i=0;i&lt;2;i++)
  {
      p1[i]=(int *) malloc(3*sizeof(int));
      for(int j=0;j&lt;3;j++)
      {
         scanf("%d",(p1+i)+j);
      }
  
  }
  for(int i=0;i&lt;2;i++)
  {
  
      for(int j=0;j&lt;3;j++)
      {
         printf("%d\n",*(*(p1+i)+j));
      }
  
  }
  </code></pre>
  
  <hr/>
  
  <p>as i have declared a double pointer (**p1) for it and i am able to put data at all those places using my scan <code>scanf("%d",(p1+i)+j);</code> statement. And to dereference i can use print statement as i have done <code>printf("%d\n",*(*(p1+i)+j));</code></p>
  
  <p>but why it is breaking during print statement but accepting my scan statement.</p>
  
  <p>but why this is giving me correct response...</p>
  
  <pre><code>int mybox[][4]={{1,2,3,4},{5,6,7,8}};//we have to provide subscript;
  for(int i=0;i&lt;2;i++){
       for(int j=0;j&lt;4;j++){
          printf("%d",mybox[i][j]);//will print all elements
          }
  }
          printf("%d",*(*(mybox)+1));//give me 2
          printf("%d",*(*(mybox+1)+1));//give me 6
          printf("%d",*(*(mybox+1)+3));//give me 8
  </code></pre>