Hello ppl,
Does anyone know the largest 2D array possible in `C`.
So if there is arr[a][b], what are the limitations on the values of a and b ??
Cheers guys, appreciate it as always !!
|
Mentor
|
![]() |
| 21Oct2008,21:58 | #2 |
|
Depends on the platform. a and b are integers, so presumably the maximum allowed by the language is 2^32-1. But (2^32-1)^2 is a LOT of memory, 16 exabytes to be precise, so the chances are you're limited by RAM first, then secondly stack or heap space depending how you declare it.
|
|
Go4Expert Member
|
|
| 22Oct2008,00:35 | #3 |
|
So I take it that I need to check the following for array size restrictions..
1) RAM 2) Stack/heap space depending on declaration Can you explain a bit about point 2) - What do you exactly mean by how I declare it ?? Thanks again. |
|
Mentor
|
![]() |
| 22Oct2008,03:32 | #4 |
|
Code:
int main()
{
int *arr1=malloc(100*sizeof(int));
int arr2[10][10];
return 0;
}
So if you have a small stack and a large heap you will need to malloc large arrays. Conversely if you have a large stack and a small heap then you can plonk the array on the stack, provided that you don't want to keep it after the function has returned. |

