title: Segmentation fault 11 because of a 40 MB array in C
body: <p>I'm trying to code something in C on my mac, and I ran into a <code>Segmentation Fault: 11</code>. I've located the problem to be the declaration of a <code>double</code> array of 5 million elements. For instance, the following code gives a <code>Segmentation Fault</code>:</p>
  
  <pre><code>int main(){
      double vals[5000000];
      return 0;
  }
  </code></pre>
  
  <p>My first question is, is <code>8*5000000 bytes</code> = <code>40 MB</code> too large? I also tried to run this on another machine (linux), which ran smoothly. So the second question is, what determines the memory available to the application? Does it have to do with the available RAM on the machine (my mac has <code>16 GB</code>, the linux machine has <code>62 GB</code>)? Or does it have something to do with the compiler options (I'm using <code>gcc</code> without any options on both machines, but different versions).</p>
  
  <p><strong>Edit:</strong> Okay, so I've changed the test code to the following because in the actual code the variable is not unused:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(){
     double vals[5000000];
     vals[0] = 500;
  
     printf("%lf\n",vals[0]);
  
     return 0;
  }
  </code></pre>
  
  <p>Also, I compile without any options/optimizing: <code>gcc test.c</code>.</p>
  
  <p>(I'm also wondering if the downvoter actually realized I'm asking more than "oh, why am I getting a segmentation fault?" like all the other questions out there.)</p>