Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

Qualified's blog

By Qualified, history, 6 weeks ago, In English,

Is there a difference between std::array like array<int, 2> MyArray = {1, 2}; and int arr[2] = {1, 2}; Time complexities? Different functionalities?

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it -9 Vote: I do not like it

No, std::array is used in something like

std::map<int, array<int, 2>>mp;
mp[1] = {3, 4};

In the other hand if you used std::map<int, vector<int>>mp; you have to assign the size before pushing values

»
6 weeks ago, # |
Rev. 2   Vote: I like it +7 Vote: I do not like it

The benefit of std::array is that you can use it like a usual object. For example, you can assign std::arrays to each other, you can pass them to functions without them decaying to pointers, and you can return them from functions. You can also put them in other standard library containers. You can't do any of these with a plain old array.