I just learnt about vectors and I'm confused about their use.
Please tell me what is the difference between:
vector<int> a;
,
vector<int> a[n];
and
vector<int> a(n);
I just learnt about vectors and I'm confused about their use.
Please tell me what is the difference between:
vector<int> a;
,
vector<int> a[n];
and
vector<int> a(n);
vector<int> a; declares an empty vector.
vector<int> a[n]; declares an array containing n empty vectors.
vector<int> a(n); declares a vector containing n zeroes.
Bonus:
vector<int> a{n}; declares a vector containing the single element n.
vector<int> a;
Declaration of a vector of ints named a
vector<int> a[n];
Declaration of an array of vectors of ints named a with n elements.
vector<int> a(n);
Declaration of a vector of ints a initialized to n number of 0s.