Weird behavior by vector STL in C++

Правка en1, от temp_ac, 2020-05-02 20:02:55

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 ?

Теги c++, vector, c++ stl

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский temp_ac 2020-05-02 20:04:21 458
en1 Английский temp_ac 2020-05-02 20:02:55 759 Initial revision (published)