the difference between arrays and vectors | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

the difference between arrays and vectors

arrays

14th Jun 2016, 10:09 AM
Sardor
Sardor - avatar
5 Answers
+ 4
- can be assigned (while in arrays u do it through every single element ) - can be copied - can be returned by functions
14th Jun 2016, 5:32 PM
Sardor
Sardor - avatar
+ 2
array has static size, while vector can change its size during program execution
14th Jun 2016, 11:34 AM
Igor Lihachev
Igor Lihachev - avatar
+ 2
good bro now i will add some more differences hit an upvote (like) if u agree
14th Jun 2016, 5:31 PM
Sardor
Sardor - avatar
+ 1
There is an array inside a vector but not the other way around.
16th Jun 2016, 8:13 PM
VPA
VPA - avatar
0
he key difference between Arrays and Vectors in Java is that Vectors are dynamically-allocated. They aren't declared to contain a type of variable; instead, each Vector contains a dynamic list of references to other objects. . When a Vector is instantiated, it declares an object array of size initial Capacity. Top 10 differences in Vector and List of C++: 1.Vector has contiguous memory 2.List has noncontiguous memory. 3.Vector Pre allocates space for future. 4.List doesn’t pre allocates space for future. 5. A list is not synchronized while a vector is. 6. Lists have no default size while a vector has a default size of 10. 7. Lists and vectors are both dynamically growing arrays. 8. A list is not thread safe whereas a vector is thread safe. 9. Lists, as they apply only to addition and deletion in the front and rear, are faster while vectors take more CPU. 10. A vector grows by its size twice while a list decreases to half, i.e., 50 per cent. Differences between a Vector and an Array - A vector is a dynamic array, whose size can be increased, where as an array size can not be changed. - Reserve space can be given for vector, where as for arrays can not. - A vector is a class where as an array is not. - Vectors can store any type of objects, where as an array can store only homogeneous values. Advantages of Arrays: - Arrays supports efficient random access to the members. - It is easy to sort an array. - They are more appropriate for storing fixed number of elements Disadvantages of Arrays: - Elements can not be deleted - Dynamic creation of arrays is not possible - Multiple data types can not be stored Advantages of Vector: - Size of the vector can be changed - Multiple objects can be stored - Elements can be deleted from a vector Disadvantages of Vector: - A vector is an object, memory consumption is more.
8th Aug 2018, 2:21 AM
deepak sharma
deepak sharma - avatar