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

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

1335


Is c++ primer good for beginners?

1046


How can you differentiate between inheritance and implementation in c++?

1222


What c++ is used for?

1102


What does it mean to declare a member function as static?

1067


What are the advantages of pointers?

1070


What is function overriding in c++?

1074


What is c++ flowchart?

1397


What are the advantages of c++?

1903


What does obj stand for?

1180


Is c++ a float?

1072


What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?

1125


What is basic if statement syntax?

1096


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

1119


what is upcasting in C++?

1189