What is the difference between vector<int> a , vector<int> a[n] and vector<int> a(n)?

Anish Vijay :

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);
emlai :

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=398689&siteId=1