I wonder what is the maximal array size in C, weither it depends on the type of data, and if it depends where it is declared (heap or stack).
The following code works with int
up to a size of 1048576 (2^20), also 1048577 (same + 1), but not with 2097152 (2^21) - I have not searched for the precise limit:
#include <stdio.h>
#define MAX 1048577llu /* 2097152llu */
int main()
{
int tab[MAX];
/* long long int tab[MAX] */
tab[MAX - 1] = 123;
printf("tab[%llu] declared, tab[%llu] = %d\n", MAX, MAX - 1, tab[MAX - 1]);
return 0;
}
With long long int
, it fails at 2^20, but succeeds at 2^19.