title: Trying to multiply two large matrixes of dimension 1000*1000 causes Segmentation Fault
body: <p>Trying to multiply two matrices of the dimension <code>1000*1000</code> . However, trying to do so causes <code>Segmentation fault</code>. what is possibly causing this and how to resolve it? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;time.h&gt;
  int main()
  {
  clock_t t;
      t = clock();
     long int a[1000][1000], b[1000][1000], result[1000][1000], r1=1000, c1=1000, r2=1000, c2=1000, i, j, k;
  
     // Column of first matrix should be equal to column of second matrix and
    /*  while (c1 != r2)
      {
          printf("Error! column of first matrix not equal to row of second.\n\n");
          printf("Enter rows and column for first matrix: ");
          scanf("%d %d", &amp;r1, &amp;c1);
          printf("Enter rows and column for second matrix: ");
          scanf("%d %d",&amp;r2, &amp;c2);
      }
  */
  
      // Storing elements of first matrix.
      printf("\nEnter elements of matrix 1:\n");
      for(i=0; i&lt;r1; ++i)
          for(j=0; j&lt;c1; ++j)
          {
            a[i][j]=rand()%20;
          }
  
      // Storing elements of second matrix.
      printf("\nEnter elements of matrix 2:\n");
      for(i=0; i&lt;r2; ++i)
          for(j=0; j&lt;c2; ++j)
          {
              b[i][j]=rand()%20;
          }
  
      // Initializing all elements of result matrix to 0
      for(i=0; i&lt;r1; ++i)
          for(j=0; j&lt;c2; ++j)
          {
              result[i][j] = 0;
          }
  
      // Multiplying matrices a and b and
      // storing result in result matrix
      for(i=0; i&lt;r1; ++i)
          for(j=0; j&lt;c2; ++j)
              for(k=0; k&lt;c1; ++k)
              {
                  result[i][j]+=a[i][k]*b[k][j];
              }
   // Displaying the result
      printf("\nOutput Matrix:\n");
      for(i=0; i&lt;r1; ++i)
          for(j=0; j&lt;c2; ++j)
          {
              printf("%ld  ", result[i][j]);
              if(j == c2-1)
                  printf("\n\n");
          }
  t = clock() - t;
      double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
  
      printf("\n \nfunction took %f seconds to execute \n", time_taken);
      return 0;
  }
  </code></pre>