Hi I was experiment with my code I made an array of long that was of size 10e9 when I declared it in main it showed segmentation error and when I just declared it outside main as a global it worked fine . Why is that so?
Maximum size of array that can be made in main?
In main the array is allocated on stack. The default limit for stack size is 8MB. so stack overflow happens.
The global array is allocated on data segment. The data segment size is by default unlimited as far as there is available memory.
So it is possible to make larger global arrays.
1 Like
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.