create myarray[3][3]
random them and i got :
1 2 3
4 5 6
7 8 9
meh ... then i cout myarray[1][4] and the number should have be zero cause it not has been set yet but it print 4 which is myarray[2][1] !!!
my concept was some thing like this
how myarray look like :
1 2 3 0 0 0 0 0 0 ...
4 5 6 0 0 0 0 0 0 ...
7 8 9 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 ...
i already done some test :
cout myarray[1][5] and got 5 which is myarray[2][2]
cout myarray[1][9] and got 9 which is myarray[3][3]
then cout myarray[1][10] and i got zero !!!
is Multi-dimensional Arrays look like cycle ?
like
1 2 3 4 5 6 7 8 9 0
4 5 6 ... not tested yet
7 8 9 ... not tested yet
???
Arrays are pointers to a specific set of memory. When you have an array of int arr[3] it is a set of 3 sequential memory slots. Array indices can be accessed with regular array notation arr[2] or with pointer notation *(arr+2). So, when you do arr[3] which is not part of the array, it is doing *(arr+3) or trying to deference the next piece of memory. Normally, your compiler will catch the error, and give you an argument out of range exception. However, since your array is two-dimensional, the next piece of memory is from the second part of the array. So, doing arr[0][4] is the equivalent of *(arr+4) or arr[1][1].
Normally, your compiler will catch the error, and give you an argument out of range exception.
No, the compiler will not usually catch out of bounds array access problems. This is why C++ has std::vector and std::array because using raw arrays it is easy to overflow the bounds of your array. And by the way arrays are arrays not pointers, although arrays do decay easily to pointers, there are differences between pointers and arrays.
In a simple array like this, the elements of each row are normally placed in consecutive locations of memory. A 2D array can be thought of as a 1D array where the compiler knows how many elements are in each row.