The question seems easy but i couldn't find any answer. So, what's the difference between int Array[10]
and array<int, 10> Array
?

- 4,584
- 4
- 26
- 37

- 111
- 1
- 8
2 Answers
In C++ there are numerous ways to create arrays. int Array[10];
will create an array similar to a C array. This means that there are a lot of memory problems inherent to it. array<int, 10> Array;
is C++ wrapping of the former array and removes the memory problems. Additionally, the C++ version is more adept in doing iteration, bounds checking, and a few other minor features. While they both will do the same thing in the end, unless you are doing something which specifically requires a C array I would go with the C++ and it will save you a lot of headaches.

- 1,700
- 1
- 8
- 15
-
You may like to elaborate on _lot of memory problems_. – Maxim Egorushkin Sep 23 '19 at 13:50
int Array[10]
is a c-style array declaration which raw memory and if you want to operate on the array you will have to write your own functions.
array<int, 10> Array
is a C++ style array declaration using the std::array
class which is an STL container
.
The later provides a lot of predefined methods to operate on the array, for example to find out how many elements are there in the array, you just need to say Array.size()
. However in case of the former you may have to write your own function to iterate over the array to find out the size.

- 4,584
- 4
- 26
- 37