C++ Array vs vector <p>when using C++ vector, time spent is 718 milliseconds, while when I use Array, time is almost 0 milliseconds.</p> <p>Why so much performance difference?</p> <pre><code>int _tmain(int argc, _TCHAR* argv[]) { const int size = 10000; clock_t start, end; start = clock(); vector&lt;int&gt; v(size*size); for(int i = 0; i &lt; size; i++) { for(int j = 0; j &lt; size; j++) { v[i*size+j] = 1; } } end = clock(); cout&lt;&lt; (end - start) &lt;&lt;" milliseconds."&lt;&lt;endl; // 718 milliseconds int f = 0; start = clock(); int arr[size*size]; for(int i = 0; i &lt; size; i++) { for(int j = 0; j &lt; size; j++) { arr[i*size+j] = 1; } } end = clock(); cout&lt;&lt; ( end - start) &lt;&lt;" milliseconds."&lt;&lt;endl; // 0 milliseconds return 0; } </code></pre>