What is the Difference between "vector" and "array"?

Answer Posted / mms zubeir

First, a vector is a template class but not the array is.
So obviously there are members to access the elements of
the vector like, range checking, iterators,
insertion/deletion, predicates, etc.

Since it is a template class, the same implementation can
be used for any type including pointers, objects/user
defined types.

Second, as said by others, vector automatically grow as we
invoke push_back(), we can reserve additional space for
elements, etc.

Is This Answer Correct ?    18 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are static variables?

614


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

784


What is the main purpose of c++?

539


Is c++ the hardest programming language?

634


What is auto used for in c++?

563






What are c++ storage classes?

614


Is it possible to use a new for the reallocation of pointers ?

591


What is class and structure in c++?

554


Is c++ double?

556


What is a .lib file in c++?

564


What is conditions when using boolean operators?

594


What is cout flush?

564


Can malloc be used in c++?

566


Explain virtual destructor?

670


Is rust better than c++?

599