title: Why on declaring an array global in c++, the size that it can be given is larger than declaring it in main
body: <p>On declaring array as global i can give its size as 5000000 bt it is not possible when i declare it in main  why?</p>
  
  <p>works fine</p>
  
  <pre><code>#include&lt;iostream&gt;
  
  int arr[5000000];
  using namespace std;
  int main()
  { 
    arr[0]=1;
    cout&lt;&lt;arr[0];
    return 0;
  }
  </code></pre>
  
  <p>segmentation fault</p>
  
  <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  int main()
  {
    int arr[5000000];
    arr[0]=1;
    cout&lt;&lt;arr[0];
    return 0;
  }
  </code></pre>