# What's the difference between Array and Vector

• 03-21-2002
ampalfe
What's the difference between Array and Vector
I'm a total newbie when it comes to programming. I was too dumb to teach myself so I'm taking C++ in Highschool. I just kinda wanted to know the difference between vector ( our teacher uses AP classes *scoffs* ) and Array? What events warrant the use of one or the other? (if there's a difference)

Thanks.

PS I'm prabobly wasting your time. Being such a newbi and all.:rolleyes:
• 03-21-2002
vectors are self expanding arrays. They are available in standardized format via the standard template libraray which is available on most up to date (latest version) compilers from the major C++ compiler makers.

You need to declare the amount of memory to be set aside for an array at compile time like this:

typename arrayname[sizeofarraywhichmustbeaconstant];

These requirements are not necessary for a vector. The vector class uses dynamic memory to allow you to write an "unlimited" size array. The vector class also has a number of methods that allow you to manipulate arrays in standard fashion like sort, reverse, insert, delete, etc. When using arrays you have to write the code to do this stuff.

Using arrays is sort of like being a chef in a restaurant whereas using vectors is sort of like being the customer in a restaurant.
• 03-21-2002
Evil Robot
Vectors mean you don't have to do as much work :)
• 03-22-2002
ninebit
Except being array-like, a vector could also be a position in space (2D or 3D). If you find the word vector when reading about computer graphics it is not the array-like vector but the point-in-space vector they're talking about. Often named vector2 or vector3 to tell if there is two or three axis.

I guess this wasn't the kind of vectors you were asking for, but now you know about the other kind of vectors to!
• 03-22-2002
Imperito
Additionally, STL classes offer optimised functions for common tasks. For example, sort()'ing a list<> is much simpler than defining a sort routine for an array, and probably faster.