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
Is c the same as c++?
What is the type of this pointer in c++?
What is the difference between prefix and postfix versions of operator++()?
What is c++ good for?
What is an arraylist c++?
What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor
Who made c++?
Is it legal in c++ to overload operator++ so that it decrements a value in your class?
Describe about storage allocation and scope of global, extern, static, local and register variables?
How a new operator differs from the operator new?
What is the difference between the parameter to a template and the parameter to a function?
what are the characteristics of Class Members in C++?
Define pre-condition and post-condition to a member function in c++?
What is setw manipulator in c++?
What do you mean by function pointer?