Creating a matrix with runtime dimentions as input
<p>There are two cods that I have written. One works while the other wont. Please explain the working of this code wand why the latter isnt working.</p>

<p>Working -</p>

<pre><code>    #include &lt;stdio.h&gt;
#include &lt;malloc.h&gt;

int main(){
  int m, n, i, j;
  scanf("%d%d",&amp;m,&amp;n);
  int *p;
  p = (int *) malloc(m*n*sizeof(int));
  for(i=0;i&lt;m;i++){
    for(j=0;j&lt;n;j++){
      scanf("%d", (p+i*n+j));
    }
  }
}
</code></pre>

<p>Not Working - </p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;malloc.h&gt;

int main(){
  int m, n, i, j;
  scanf("%d%d",&amp;m,&amp;n);
  int *p;
  p = (int *) malloc(m*n*sizeof(int));
  for(i=0;i&lt;m;i++){
    for(j=0;j&lt;n;j++){
      scanf("%d", p[i][j]);
    }
  }
}
</code></pre>

<blockquote>
  <p>error is - subscripted value is neither array nor pointer nor vector<br>
  scanf("%d", p[i][j]);</p>
</blockquote>