Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Is c the same as c++?

951


What is the type of this pointer in c++?

1005


What is the difference between prefix and postfix versions of operator++()?

1023


What is c++ good for?

998


What is an arraylist c++?

1150


What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor

1099


Who made c++?

1013


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

1006


Describe about storage allocation and scope of global, extern, static, local and register variables?

1197


How a new operator differs from the operator new?

1056


What is the difference between the parameter to a template and the parameter to a function?

1057


what are the characteristics of Class Members in C++?

992


Define pre-condition and post-condition to a member function in c++?

1084


What is setw manipulator in c++?

1010


What do you mean by function pointer?

1037