top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the advantages of Vector over an array in C++?

+4 votes
619 views

What are the advantages of Vector over an array in C++? give Exmaple.

posted Apr 27, 2016 by Shahsikant Dwivedi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 
Best answer

If you mean over C-style arrays, I'd say it's ease of management. I remember when I wrote my first solution for TC problem I tried to use C-style arrays - and then a friend showed me vectors, and I was immediately impressed by how much shorter and cleaner my solution became. C-style arrays are fixed-length, and you have to keep track of their actual length (if you're generating elements one by one up to certain quantity), to worry about how much you should allocate beforehand, to handle pointers when passing them as params and when having them multi-dimensional. vectors can be resized at will, have lots of useful algorithms in STL (sorting, search, removing duplicates etc.) and are generally easier to handle.

answer Apr 28, 2016 by Shivaranjini
...