title: Segmentation Fault, c program
body: <p>Why does these code returning a segmentation fault? I searched online but can't find the problem. Could you please help?
  Is it because of pointer malloc fault?</p>
  
  <pre><code>void multiply(int **a, int n, int m, int **b, int m2, int p, int **c)
  {
      int i, j, k;
      for (i = 0; i &lt; n; i++){
          for (j = 0; j &lt; p; j++){
              for (k = 0; k &lt; m; k++){
                  c[i][j] += a[i][k] * b[k][j];
                  }
              printf("%d", c);}}
  }
  main()
  {
      int **a, **b, **c;
      int n, m, p;
      int i, j;
      scanf("%d", &amp;n); scanf("%d", &amp;m); scanf("%d", &amp;p);
      a = (int **)malloc(n*sizeof(int*));
      for (i = 0; i &lt; n; i++){
          a[i] = (int*)malloc(m*sizeof(int));}
      for (i = 0; i &lt; n; i++){
          for (j = 0; j &lt; m; j++){
              scanf("%d", &amp;a[i][j]);}
      }
      b = (int **)malloc(m*sizeof(int*));
      for (i = 0; i &lt; m; i++){
          b[i] = (int *)malloc(p*sizeof(int));}
      for (i = 0; i &lt; m; i++){
          for (j = 0; j &lt; p; j++){
              scanf("%d", &amp;b[i][j]);}
      }
      c = (int **)malloc(n, sizeof(int));
      for (i = 0; i&lt;n; i++)
          c[i] = (int *)malloc(p, sizeof(int));
      multiply(a, n, m, b, m, p, c);
      free(a);
      free(b);
      free(c);
  }
  </code></pre>
  
  <p>Thanks^^</p>
  
  <p>I edit some code and it is now correct. Thank you guys so much.
  Cheers!</p>