Dynamic 2d array allocation error

#include
using namespace std;
int main() {
int n,m;
cin>>n>>m;
int arr = new int[n];
for(int i=0;i<n;i++) {
arr[i] = new int[m];
}

for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
        cin>>arr[i][j];
    }
}


return 0;

}

error is
‘int*’ in initialization
int arr = new int[n];
^
subarr.cpp:8:18: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
arr[i] = new int[m];
^~~~~~~~~~
subarr.cpp:13:26: error: invalid types ‘int[int]’ for array subscript
cin>>arr[i][j];
^

Hello @kartikaydwivedi55 i have corrected your code.
for 2-D Allocation it should be of type pointer to pointer.


if you have any doubt you can ask here:
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.