It crashes because you write beyond the end of the vector with v[0] - that is undefined. Its actual size is 0 if you are not doing anything. (You also read the same, but all bets come out well before that point).
You probably wanted to:
vector<int> v; v.push_back(25); foo(v);
Or maybe:
vector<int> v(1); v.at(0) = 25; foo(v);
If you use v.at(n) instead of the [] operator, you will get an exception, not an undefined one.
source share