-1

I am doing the codecademy c++ course and just went over vectors and arrays. From what I understand, the only difference between the two is that you can change the size of a vector, but cannot change the size of an array. Are there any other differences that I am missing that would make them more useful in the future?

3
  • the only difference between the two is that you can change the size of a vector, -- Vectors do not decay to pointers when passed to functions. Commented Apr 19, 2020 at 23:57
  • @PaulMcKenzie neither does std::array. But both containers do have a data() method for getting such a pointer Commented Apr 20, 2020 at 0:45
  • I was assuming the author was referring to regular arrays, not std::array. Commented Apr 20, 2020 at 0:49

1 Answer 1

2

A major difference is that std::vector allocates memory, i.e. it uses the heap for storage. An array (std::array or a built-in one) does not.

Allocating memory is a major difference because it is a very expensive operation relative to many others (when using the default allocator).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.