Shubham Kharche Shubham Kharche - 8 months ago 31
C Question

Dealing with large arrays without getting runtime error

I am getting runtime error when I used array of size 10^5*10^5 (ex.

int a[100000][100000]
. As this array is consuming more memory, this may be one one of the reasons for runtime error.

How should I declare this array (2D array ex.
int a[100000][100000]
) so that I can cope with problem of
runtime error?

Please, provide approach to declare such type of array?


Three ways to declare the large array int a[100000][100000] are:

  1. Make the large array global
  2. Make the large array static:

    static int a[100000][100000];
  3. Use malloc/calloc and dynamically allocate the large array:

    int **a;
    for(int i=0;i<100000;i++)
    /*Use the array*/
    for(int i=0;i<100000;i++)