Possible Duplicate:
Advantages of using arrays instead of std::vector?
What are the main advantages/disadvantages of array and vector in C++? I usually find that vectors are easier to use due to their dynamic nature but sometimes it seems like arrays are faster with less overhead. Are there any other significant advantages? I usually am not sure when to use one over the other, depending.
The most obvious reason to prefer an array is to achieve static
initialization of a variable at namespace scope; static initialization
means no order of initialization issues, ever. (If you have C++11,
std::arrayprovides this as well.)The other main reason is to allow the compiler to determine the size
according to the number of initializers, without you having to count
them.