So I am just learning about two dimensional arrays and started to play around with the implementation and found something weird. Why is it that when incrementing the column one by one, every number is displayed in the dialog box.....but when incrementing the rows one by one, only the first number in each row is displayed. It's at line 14. Thanks for any response.
In each row the array has only four columns. So the llop
for(col=0; col<12;col++) //when I change col to row I get crazy numbers
cout << temp[row][col] << " ";
is incorrect
That is when you change col to row each row increment results in that you bypass 4 * iszeof( int ) memory locations.
temp[row] has type of array int[4]
So if temp[0] points to for example the address 0, then temp[1] will point to 0 + 4*sizeof( int ) that is 16. temp[2] will point to 16 + 16 = 32 and so on.
Thanks for the response but despite line 14 being wrong, the program still prints out every number which is why it is so weird. That's the crutch of my problem......just curious as to how it manages to do so.
EDIT: I just got the end of your last message vlad from moscow. I get it now. Thanks again
Arrays are placed in memory rows by rows. Your original array has only 3 rows. So when you set index of the row greater than 2 you are trying in fact to acces memory beyond your array.