title: Displaying contents of a vector container in C++
body: <p>The following is a C++ program using STL vector container. Just wanted to know why the  display() function is not printing the vector contents to the screen. If displaying the size() line is commented out, display() function works fine.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  void display(vector&lt;int&gt; &amp;v)
  {
      for(int i; i&lt;v.size(); i++)
      {
          cout &lt;&lt; v[i] &lt;&lt; " ";
      }
      cout &lt;&lt; "\n" &lt;&lt; endl;
  }
  
  int main()
  {
      vector&lt;int&gt; v;
      cout &lt;&lt; "Size of Vector=" &lt;&lt; v.size() &lt;&lt; endl;
  
      //Putting values into the vector
      int x;
      cout &lt;&lt; "Enter five integer values" &lt;&lt; endl;
      for(int i; i&lt;5; i++)
      {
          cin &gt;&gt; x;
          v.push_back(x);
      }
      //Size after adding values
      cout &lt;&lt; "Size of Vector=" &lt;&lt; v.size() &lt;&lt; endl;
  
      //Display the contents of vector
      display(v);
  
      v.push_back(6);
  
      //Size after adding values
      cout &lt;&lt; "Size of Vector=" &lt;&lt; v.size() &lt;&lt; endl;
  
      //Display the contents of vector
      display(v);
  
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Size of Vector=0
  
  Enter five integer values
  
  1
  
  2
  
  3
  
  4
  
  5
  
  Size of Vector=5
  
  
  Size of Vector=6
  </code></pre>