viral
viral

Reputation: 4208

What does "C-style array" mean and how does it differ from std::array (C++ style)?

I came across this question, while reading about std::array and std::vector.

Upvotes: 21

Views: 34917

Answers (1)

Seth Carnegie
Seth Carnegie

Reputation: 75130

A C-Style array is just a "naked" array - that is, an array that's not wrapped in a class, like this:

char[] array = {'a', 'b', 'c', '\0'};

Or a pointer if you use it as an array:

Thing* t = new Thing[size];
t[someindex].dosomething();

And a "C++ style array" (the unofficial but popular term) is just what you mention - a wrapper class like std::vector (or std::array). That's just a wrapper class (that's really a C-style array underneath) that provides handy capabilities like bounds checking and size information.

Upvotes: 24

Related Questions