0

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?

Sisir
  • 4,584
  • 4
  • 26
  • 37
Konstantin
  • 111
  • 1
  • 8

2 Answers2

0

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.

Jake Freeman
  • 1,700
  • 1
  • 8
  • 15
0

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.

Sisir
  • 4,584
  • 4
  • 26
  • 37