Please refer the image below.
Why we make array like this and how it’s different from int solution[n] [n] ?

Please help me out. Thanks in advance.
Please refer the image below.
Why we make array like this and how it’s different from int solution[n] [n] ?

Please help me out. Thanks in advance.
Hey @gambhirrahul0 int **arr = new int [n] is a way to declare 2 D array dynamically. As arr[n][n] is static allocation whereas int **arr = new int [n] is dynamic allocation.
Thanks! Will you please explain the working of those 4 lines in more detail?
So what it does is, in the first line you are declaring n pointers name arr . See it like this
int *(*arr) = new int [n]
Just think *arr as p so you will get the intuition of dynamically declaring a 1d array . Since your p is a pointer and you have n pointers .
You run a for loop and declare p[i] = new int [n] which looks like
int arr[i] = new int [n] now this is 1d dynamic allocation.
If you have any more doubts left regarding this then do let me know.
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.