title: Max array size using #define
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14182127/stack-overflow-c">stack overflow c++</a>  </p>
  </blockquote>
  
  
  
  <p>I have the following program for generating prime numbers: </p>
  
  <pre><code>#include&lt;iostream&gt; 
  #include&lt;cmath&gt;
  #include&lt;algorithm&gt;
  
  #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&lt;=baseSqrt;i++){
          if(prime[i]){
              for(j=i+i;j&lt;=MAX;j+=i){
                      prime[j]=false;
              }   
          }   
      }   
      return 0;
  }
  </code></pre>
  
  <p>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.</p>