title: C++: "vector<int>::size_type variable" - what is the point of declaring in this way?
body: <p>I think this is a very basic question but I couldn't just figure it out.</p>
  
  <p>I was used to using arrays in C++ but I'm now starting to learn vectors.
  I was making a test code, and I came across a question.</p>
  
  <p>First of all, here's the code I made:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;numeric&gt;
  using namespace std;
  
  int main(){
    vector&lt;double&gt; score(10);
  
    for(vector&lt;double&gt;::size_type i=0;i&lt;20;i++) {
      cout&lt;&lt;"Enter marks for student #"&lt;&lt;i+1&lt;&lt;":"&lt;&lt;flush;
      cin&gt;&gt;score[i];
    }
  
    double total = accumulate(score.begin(), score.end(),0);
  
    cout&lt;&lt;"Total score:"&lt;&lt;total&lt;&lt;endl&lt;&lt;"Average score:"&lt;&lt;total/score.size()&lt;&lt;flush;
  
    return 0;
  }
  </code></pre>
  
  <p>In the <code>for</code> sentence in line #9, I am declaring <code>i</code> as a <strong><code>vector&lt;double&gt;::size_type</code></strong> type (because I was told to do so).
  I tested the code with the type said above replaced with an <strong><code>int</code></strong>, and it worked perfectly fine.
  Why is <strong><code>vector&lt;double&gt;::size_type</code></strong> preferred compared to <strong><code>int</code></strong>?</p>