Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your matrices are too big for the stack on your machine. Each of the arrays has 4 million integers, or roughly 16 MiB of storage; that is a very big stack requirement.</p> <p>Either reduce their size or allocate them dynamically.</p> <p>Or (as noted in the comments), make them into variables with 'static duration', either within <code>main</code> with the keyword <code>static</code> in front:</p> <pre><code>int main(int argc, char *argv[]) { int row1, row2, col1, col2, i, j, cnt=0; static int mat1[2000][2000], mat2[2000][2000]; </code></pre> <p>or as file scope variables defined outside <code>main()</code>, also with the keyword <code>static</code> in front:</p> <pre><code>static int mat1[2000][2000], mat2[2000][2000]; int main(int argc, char *argv[]) { int row1, row2, col1, col2, i, j, cnt=0; </code></pre> <p>or as global variables defined outside <code>main()</code> without the keyword <code>static</code> (but only do this if you will have multiple source files that need to access them by name):</p> <pre><code>int mat1[2000][2000], mat2[2000][2000]; int main(int argc, char *argv[]) { int row1, row2, col1, col2, i, j, cnt=0; </code></pre> <p>You could also (again, as noted in the comments) increase the stack size. However, I respectfully suggest that is probably the least satisfactory solution.</p> <blockquote> <p>How to dynamically allocate the size of an array?</p> </blockquote> <p>Fair question. How often do you think you'll really need a pair of 4 million cell arrays, compared with how often will you be dealing with, say, under 100x100 arrays? Also, are you on Windows (with MSVC and C89) or non-Windows (with C99 or later), or on Windows with GCC?</p> <p>Also, have you learned about pointers yet?</p> <p>On the whole, I think you should opt for smaller size arrays. That is by far the simplest solution. If you must have big arrays, go with statically allocated arrays.</p> <p>If that won't work, we'll have to go through the pointers, but it isn't pretty.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload