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

What is c++ hiding?

1137


What is a memory leak c++?

1080


Refer to a name of class or function that is defined within a namespace?

1065


how to access grid view row?

2185


What are the types of pointer?

1052


What is the best c++ book for beginners?

1107


Difference between struct and class in terms of access modifier.

1164


What are the basic data types used in c++?

1014


What is a base class?

1063


Why are arrays usually processed with for loop?

1201


What is the role of C++ shorthand's?

1245


How does list r; differs from list r();?

1108


what are the iterator and generic algorithms.

1924


Explain operator overloading.

1018


What is rtti in c++?

1087