What is the Difference between "vector" and "array"?
Answer Posted / sumit arora
In C++,vectors are used for dynamically allocating space
(run time)as per your need,you do not need to hard code for
eg: consider a <vector> v;
for(int i=0;i<=v.size();i++)
cout<<v[i];
and that size can be increased with v.pushback(element)for
eg.
so there is no need to hard code whatever element you
pushed back only that memory is used.
but in array you do only have a fixed size
for(i=0;i<=100;i++)
cin<<a[i];
and if you want to access a[101] positions also it will
show you a garbage value ,bcoz in array there is no bound
checking and memorywize its a compile time allocation not a
dynamic one.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.
Is c++ primer good for beginners?
How can you differentiate between inheritance and implementation in c++?
What c++ is used for?
What does it mean to declare a member function as static?
What are the advantages of pointers?
What is function overriding in c++?
What is c++ flowchart?
What are the advantages of c++?
What does obj stand for?
Is c++ a float?
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?
What is basic if statement syntax?
Refer to a name of class or function that is defined within a namespace?
what is upcasting in C++?