-1
#include <bits/std c++.h>
using namespace std;
int main () {
int n; cin>>n;
vector<vector<int>> array[n];//idk what this is`
vector<vector<int>> arr(n);//this means size of array is n
please tell me difference between them
}

I am new at coding but I am not really getting what this is so please help me

  • 2
    Does this answer your question? [What is the difference between vector a , vector a\[n\] and vector a(n)?](https://stackoverflow.com/questions/61014089/what-is-the-difference-between-vectorint-a-vectorint-an-and-vectorint) or https://stackoverflow.com/questions/26073735/square-brackets-in-vectors – user17732522 Mar 29 '22 at 10:13
  • 3
    OT: Whoever told you about [``](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) is wrong. – Jabberwocky Mar 29 '22 at 10:18

1 Answers1

1

The statement:

vector<vector<int>> array[n];

creates an array named array of size n with elements of type vector<vector<int>>. That is, each of the element inside this array is a 2D vector.

While the statement:

vector<vector<int>> arr(n);

creates a 2D vector with n elements each of which is a 1D std::vector<int>.

Jason
  • 36,170
  • 5
  • 26
  • 60