Probably because the push_back in the first case caused an internal reallocation in the vector thus all its iterators were invalidated. To see if this is the case, reserve a bunch of space in the vector at the beginning of main by doing arrayOfInts.reserve(10); for example and try the first version of addNewInts(). That should side step the seg fault.