it works properly however it is unable to generate prime numbers up to 1 million or so as i would get a stack overflow

i hope some pro can help point out why it causes a stack overflow and how to prevent it in the future.

Heres my code btw:

int genPrimes(long primes[], long primeSize){ long sum = 0; for (long i = 2; i < primeSize; i++){ if (primes[i] == 0 || primes[i] == 1){ continue; } int currentPrime = primes[i]; cout << currentPrime << " "; sum += currentPrime; for (long k = 2; k < primeSize; k++){ if (primes[k] % currentPrime == 0){ primes[k] = 1; } } } return 1; }