int* A= new int [l*m];
for (int i = 0; i<l;i++) {
for (int j=0;j<m;j++){
*(A +i*m+j)=(rand()%9)+1;}}
for (int i = 0; i<l;i++) {
for (int j=0;j<m;j++){
cout<<*(A+i*m+j)<<" ";}
cout<<endl;
Output of this would a 2D array size of [l][m] (will be entered through cmd line) filled with random numbers 1-9. I'm placing just an excerpt here so it's easier to read.
Why does *(A+i*m+j) work to move through a 2D array both vertically and horizontally(with for loops ofc) and could it be written differently, this syntax is confusing me?
This was for school, I know I could have done the same with an array of pointers but I really want to understand this bit of code.
Also how do I pass this 2D array as an argument to a function?
As in void arrayFunct(???){}
Thanks in advance.