Hey lads, let me ask you a really good question,
Is there a possibility to write for 2d array syntax to insert and display a 2d array "M[10][10]" using while loop and do while loop?
I know the basic form is using the for loop and i know it works perfect with it, but I am curios because I didn't find info about 2d arrays with other loop then for.
int *p declares a pointer to an int; i.e. a variable that can hold the address of an int.
The &M[0][0] is the memory address of the start of the array. For a predeclared 2-d array like this the memory is contiguous (i.e. each row will follow directly after the previous one).
The while loop runs through m x n elements. x is decremented by 1 each time (after testing); when it gets to 0 the loop stops.
Within each loop, *p is the value at the memory address pointed to by p. p++ increments the pointer, so pointing to the next element of the array.
MaxGreen, be aware that you must not collapse 2-d to 1-d if the 2-d is dynamically allocated (eg from a ** or vector<vector< ) because the rows may not be touching in memory, and cannot just skip from one to the next with a pointer math, you have to jump to the new offset. This also can cause page faults which is why I recommend avoiding 2-d dynamic memory if possible. It is FINE for a 2-d array as those are assured to be a solid block of memory (this is what you have going on, so its correct for your program).