Getting a stack overflow exception when declaring a large array

Your array is way too big to fit into the stack, consider using the heap:

int *sieve = malloc(2000000 * sizeof(*sieve));

If you really want to change the stack size, take a look at this document.

Tip: – Don’t forget to free your dynamically allocated memory when it’s no-longer needed.

Leave a Comment