I was solving a problem using C++ vector STL. But I was getting some wrong answers for my problem. Then, I started debugging my code. And after that, I noticed some weird behavior by my vector STL.
Code 1
After giving input like this : 3 5 8 10
I am getting this output : -3 0 3 8 ( why getting 0 on index 1 ? AND where is 10 ? )
And Similarly Let's see Another weird behavior ( if we don't sort the vector v AND still giving same input as of Code 1 ):
Code 2
I am getting this output : 0 3 8 10 ( why getting 0 on index 0 ? AND where is -3 ? )
Can someone explain this why I am facing this weird behavior ?