Segmentation Fault While Creating Large Arrays in C

You probably don’t have 10 megabytes of stack space. Make that array global, declare it with static, or allocate it dynamically using malloc(). If you choose the latter, don’t forget to free() it.

Later, when you need to use the 100,000,000 element array, make sure to use a new allocation for it!

Leave a Comment