Arrays vs Vectors

A vector is a dynamic array, as it can shrink and grow in size when needed, so I was just wondering if a vector is just a addition to the array, hense a array with lots more features, why would you want to use an array at all if vectors are so much more powerful thab a standard array which you are ( mot of the time ) limited to the amount of data it can hold? I have always used vectors in game programming, as they are much more friendly.

Arrays are still nessassary to learn though. This is because they're completely fundemental and found in almost all programming languages. Plus, there is still a lot of old code out there that contains arrays. If students didn't learn them, they'd have no idea what to do when they encountered them.

Perhaps I should better say: In almost all cases, there is a standard container in C++ that works more efficiently than an array.

Arrays play there part in small situations. For instance, if you had to map only a Boolean value to the index, an array of two elements would perhaps be more efficient than a container object simply because the reduction of overhead.

Basically, you are correct. The vector (or some other container) is almost always a better choice because it is safer, more robust, and often easier to use.

However, since vector is a dynamic array, you don't necessarily need its "power" if all you need is a simple constant sized local array. I would probably use a vector in those cases anyway (or std::tr1::array), but I wouldn't say its a bad idea to use the C style array.

And in some (probably more rare than you think) situations, you might get a performance boost or executable size decrease from using the local array over the dynamic array used to implement a vector. If your situation requires maximum efficiency or minimum executable size, then you might consider those reasons for using the local array.

Vectors are based directly off arrays (resizing when necessary to maintain the illusion of dynamic-ity) and trades off speed for code readability and ease of use.

I once ran a benchmark of new/delete versus vector, and the vector performed comparably to arrays in terms of initialization and access, sometimes outperforming arrays altogether. This is probably due to the compiler optimizing vector code, as a second benchmark compiled with high optimization showed a slightly larger array-vector performance gap.