1

Why does the maximum array varies from local declaration and global declaration?

I have read in some blog that maximum size of array that we can declare would be 10^6 in case of local declaration and between 10^7 to 2*10^8 in case of global declaration. What is the reason for this?

nomorequestions
  • 589
  • 2
  • 6
  • 20

2 Answers2

5

Those numbers don't mean a thing in general, they are specific to the OS + Machine. But local declaration and global declaration are done in different regions of virtual memory. The local variables are on the stack, which is generally smaller than the heap (used for dynamically allocated global variables)

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
0

Global declaration reserves memory on the static memory which is large enough to not impose a memory problem. But local declarations reserves memory on the stack which it's memory is limited. So you can't declare an array as a local object with a large amount of memory otherwise you get out of the memory range which is known as a Stack Overflow

rullof
  • 7,124
  • 6
  • 27
  • 36