title: Program seg faults on vector access
body: <p>I am a C++ newbie, learning C++ on a OS X Yosemite.</p>
  
  <p>I was declaring a vector in source file like this.</p>
  
  <pre><code>vector &lt;int&gt; v(3);
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  void printVector (vector &lt;int&gt; v) {
  
      for (int i = 0; i &lt; v.size() ; i++)
          cout &lt;&lt; v[i] &lt;&lt; endl;
  }
  
  int main (int argc, char ** argv) {
  
      vector&lt;int&gt; v(3);
  
      cout &lt;&lt; "Initialise vectors..." &lt;&lt; endl;
  
      v[0] = 10;
      v[1] = 11;
      v[2] = 12;
  
      printVector(v);
  
      v.push_back(7);
  
      cout &lt;&lt; "push back (7)" &lt;&lt; endl;
  
      printVector(v);
  
  
      return 0;
  
  }
  </code></pre>
  
  <p>Program worked.</p>
  
  <p>I then referenced this webpage <a href="http://www.cplusplus.com/reference/vector/vector/size/" rel="nofollow">here</a> and followed its way to declare the vector like this.</p>
  
  <pre><code>vector &lt;int&gt; v;
  </code></pre>
  
  <p>Compiled (using g++) fine but program segfaults 11 when executed.</p>
  
  <p>Is the website wrong?</p>