0

related question: what is difference between vector<int> v(N) and vector < int > v [N]?

similar discussion in Reddit: Difference between square brackets and parenthesis when initializing points using new?

vector<int> v(100);
vector<int> v[100];

I don't have any ideas the differences between the two. It seems like they behave exactly the same. I read above posts, but still I don't get it.

Could you tell me the differences?

c-an
  • 3,543
  • 5
  • 35
  • 82
  • 2
    Please explain which part of the linked posts you didn't understand. Otherwise all we can do is repeat all of the content there, which does not serve anyone, least of all you. tl;dr "I don't get it" is not a problem description – Lightness Races in Orbit Aug 17 '19 at 02:02
  • 3
    *It seems like they behave exactly the same* -- What code did you write that makes you believe this? Maybe that's where you should start in attempting to explain what in this is confusing to you. – PaulMcKenzie Aug 17 '19 at 02:11
  • 1
    `vector v(100);` is one vector with 100 default constructed elements. `vector v[100];` is an array with 100 empty vectors. They absolutely don't behave the same. Try `v.push_back(5)` and `v[0].push_back(5)`. And to confuse you even more there also is `vector v{100};` which also behaves different. This is one vector with one element that is constructed with the argument 100. – Thomas Sablik Aug 17 '19 at 10:46

0 Answers0