Possible Duplicate:
stack overflow c++
I have the following program for generating prime numbers:
#include<iostream>
#include<cmath>
#include<algorithm>
#define MAX 10000000
using namespace std;
int main(int argc, const char *argv[])
{
bool prime[MAX+1];
fill_n(prime,MAX+1,true);
int baseSqrt,i,j;
baseSqrt = int(sqrt(MAX+1));
for(i=2;i<=baseSqrt;i++){
if(prime[i]){
for(j=i+i;j<=MAX;j+=i){
prime[j]=false;
}
}
}
return 0;
}
The program works fine for MAX value = 1000000. But when I increase the value to 10000000 the program gives segfault. I tried using gdb but it stops on main giving segfault there. I am using a 64 bit OS. Even if I remove MAX and write 10000000 rather than MAX, I get the same error. Where am I going wrong? Please help.