[Solved] How does vector’s growth function work? [closed]


So how is the 10000th element stored here?

The element isn’t stored in the vector. It’s ‘stored’ in a piece of memory that is unrelated to the vector.

Isn’t the expected behavior here a “Segmentation fault”?

No. The behaviour is undefined, so there is no behaviour to expect.

But the above runs successfully.

That’s a possible behaviour when the behaviour is undefined.

solved How does vector’s growth function work? [closed]