Since you probably don't have enough stack memory to store this large array.
The second example creates an array on the stack, while the first example creates an array that is not on the stack, but somewhere in the data / Bss segment, because you explicitly specify storage criteria using a static classifier.
Note that the C ++ standard does not specify stack or heap or data segment or Bss segment , these are all the details defined by the implementation. The standard defines only the behavior expected from variables declared with different storage criteria. So, where the variables are actually created, the implementation is implemented, but, of course, one, both examples will create arrays in different areas of memory, and the second because of failures, because there is not enough memory in this region.
In addition, it is possible if you create an array of such huge sizes in a real implementation, your design seems erroneous, and you can think about revising it.
You might also consider using std :: array or std :: vector instead of traditional c-style arrays.
source share