| Author: UltimateRengan 25 Jul 2008 | Member Level: Diamond | Rating: Points: 1 |
First, a vector is a template class but not the array is. So obviously there are members to access the elements of the vector like, range checking, iterators, insertion/deletion, predicates, etc.
Since it is a template class, the same implementation can be used for any type including pointers, objects/user defined types.
Second, as said by others, vector automatically grow as we invoke push_back(), we can reserve additional space for elements, etc.
|
| Author: chandramohan 25 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
First, a vector is a template class but not the array is. So obviously there are members to access the elements of the vector like, range checking, iterators, insertion/deletion, predicates, etc.
Since it is a template class, the same implementation can be used for any type including pointers, objects/user defined types.
Second, as said by others, vector automatically grow as we invoke push_back(), we can reserve additional space for elements, etc
---
|
| Author: Ashok 25 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
vector is also an array but the size of a vector can change dynamically where in array its fixed.
we can create some reserve space in vector where in array we cannot.
the size of array is fixed in compile time .so the size of array cannot be adjusted at run time to accommodate changeling program . but vector can solve this problem allocating memory as needed. although vector is dynamic
A growable array is calld vector while array is of fixed size
|
| Author: Ashok 25 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
"An array is a structure that holds multiple values of the same type. The length of an array is established when the array is created. After creation, an array is a fixed-length structure. "
"The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created."
Array 1)Size of array need to be declared in advance. 2)Once declared array can't grow in size. 3)Array can store primitive data types.like int,char,... Vector 1) No need to declare the size of vector. You may give its size & you may not. 2) Vector can always grow in size if you start adding more element to it than your declared size. 3) Vector can store only object references. Storing primitive data types is not possible in case of vectors.
|
| Author: Ashok 25 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
-array: data structure used dto store a group of objects of the same type sequentially in memory - vector: container class from STL - holds objects of various types - resize, shrinks grows as elements added - bugs such as accessing out of bounds of an array are avoided
A vector is similar to an array but with extended functionality. One of the features of a vector is that if you use the at() function, an exception will be thrown if you try and access an element that doesn't exist. A vector is a template class, it is a generic array of whatever type you want it to be. This gives vectors a great deal of flexibility, they can be used as an array of anything, you can even have a vector of vectors, they are difficult to get out of bounds errors with (see Bounds checking) and they are very fast for random access. Vectors also have a number of useful functions which can tell you certain properties of the vector. For a full description of each function see functions further down the page."
|
| Author: Ratheesh 31 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
"An array is a structure that holds multiple values of the same type. The length of an array is established when the array is created. After creation, an array is a fixed-length structure. "
"The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created."
a vector is a template class but not the array is. So obviously there are members to access the elements of the vector like, range checking, iterators, insertion/deletion, predicates, etc.
Since it is a template class, the same implementation can be used for any type including pointers, objects/user defined types.
as said by others, vector automatically grow as we invoke push_back(), we can reserve additional space for elements, etc.
|
| Author: chandramohan 01 Aug 2008 | Member Level: Gold | Rating: Points: 1 |
array: data structure used dto store a group of objects of the same type sequentially in memory - vector: container class from STL - holds objects of various types - resize, shrinks grows as elements added - bugs such as accessing out of bounds of an array are avoided
A vector is similar to an array but with extended functionality. One of the features of a vector is that if you use the at() function, an exception will be thrown if you try and access an element that doesn't exist. A vector is a template class, it is a generic array of whatever type you want it to be. This gives vectors a great deal of flexibility, they can be used as an array of anything, you can even have a vector of vectors, they are difficult to get out of bounds errors with (see Bounds checking) and they are very fast for random access. Vectors also have a number of useful functions which can tell you certain properties of the vector. For a full description of each function see functions further down the page."
|