One way you can create 2d array using your approach (but it is still an 1d array) :
1 2 3 4 5 6 7
|
int n1, n2;
int *arr;
cout<<"\nEnter The Row : ";
cin>>n1;
cout<<"\nEnter The Col : ;
cin>>n2;
arr = new int[n1 * n2];
|
If you want to create an 2d array, you need a two-dimensional pointer. So you can do this :
1 2 3 4 5 6 7 8 9 10
|
int n1, n2;
int **arr;
cout<<"\nEnter The Row : ";
cin >> n1;
cout<<"\nEnter The Col : ";
cin >> n2;
int i;
arr = new int*[n1];
for(i = 0; i < n1; i++) arr[i] = new int[n2];
|
Last edited on