D
D
Daniel2018-09-14 19:31:06
C++ / C#
Daniel, 2018-09-14 19:31:06

Why does the first element of an uninitialized array point to the last element of the vector created before it?

int main(int argc, char *argv[])
{
          vector<int>v4{1,2,3,4};
           v4.push_back(889);

          array<int,3> arr;
          cout<< *(arr.begin()); // 889 . почему?

Also if you play around with the pointer. That is, output cout<< *(arr.begin()-4) // 1. and *(arr.brgin()+2)// 2.
Is this the so-called heap?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2018-09-14
@daniil14056

No reason. Accessing an uninitialized variable is undefined behavior, you cannot exploit it in your programs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question