Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

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

like image 962
viral Avatar asked Aug 20 '11 04:08

viral


People also ask

What is the difference between a C-style array and C++ array?

A C-Style array is just a "naked" array - that is, an array that's not wrapped in a class, like this: And a "C++ style array" (the unofficial but popular term) is just what you mention - a wrapper class like std::vector (or std::array ).

What does'C-style array'mean?

What does "C-style array" mean and how does it differ from std::array (C++ style)? Bookmark this question. Show activity on this post. I came across this question, while reading about std::array and std::vector. Show activity on this post. A C-Style array is just a "naked" array - that is, an array that's not wrapped in a class, like this:

What is array in C with example?

A C-style array is nothing more than a block of memory that can be interpreted as an array; it is not a defined data type. Other options are available in class libraries. Arrays must be declared by type and either by size or by some indication of the number of dimensions.

What is the difference between a structure and an array?

A structure creates a data type that can be used to group items of possibly different types into a single type. Array refers to a collection consisting of elements of homogeneous data type. Structure refers to a collection consisting of elements of heterogeneous data type. Array uses subscripts or “ [ ]” (square bracket) for element access


1 Answers

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.

like image 61
Seth Carnegie Avatar answered Oct 04 '22 04:10

Seth Carnegie