What's the difference between Array and Vector

This is a discussion on What's the difference between Array and Vector within the C++ Programming forums, part of the General Programming Boards category; I'm a total newbie when it comes to programming. I was too dumb to teach myself so I'm taking C++ ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    Question 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.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    11
    Vectors mean you don't have to do as much work

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    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!

  5. #5
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vector vs. array.
    By matsp in forum C++ Programming
    Replies: 37
    Last Post: 06-23-2008, 01:41 PM
  2. efficiency issues with downsizing vector or array
    By robatino in forum C++ Programming
    Replies: 5
    Last Post: 12-29-2006, 11:09 AM
  3. converting a vector of strings into an array.
    By LightsOut06 in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2005, 08:14 PM
  4. Array trying to be a vector
    By Chaplin27 in forum C++ Programming
    Replies: 18
    Last Post: 03-03-2005, 09:48 PM
  5. my vector class..easy dynamic arrays
    By nextus in forum C++ Programming
    Replies: 5
    Last Post: 02-03-2003, 10:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21