vector subscript out of range error strange behavior in C++ : <p>I'm starting to learn C++ so the answer to my question might be obvious to you but I am really puzzled. I expect the program would crash when accessing a out of range index but instead, the program runs just fine. Here is the code.</p>

<pre><code>    #include &lt;iostream&gt;
    #include &lt;typeinfo&gt;
    #include &lt;string&gt;
    #include &lt;vector&gt;

    using namespace std;

    int main() {
        int x;
        vector&lt;int&gt; v1;

        while (cin &gt;&gt; x) {
            v1.push_back(x);
        }

        cout &lt;&lt; "out of bound: " &lt;&lt; v1[10] &lt;&lt; endl;
    return 0;
}
</code></pre>

<p>And here is the output:</p>

<pre><code>1 2 3
out of bound: 0
</code></pre>
