Multidimensionality Arrays indirect interaction

I extracted the problem, I don't understand why cout <Array [0] [8] writes 2 instead of 1.

http://gyazo.com/d159d3ea97b07f1551605daacd631703

#include <iostream>
using namespace std;

int main()
{
    int Array[8][8];

    Array[0][8] = 1;
    Array[1][0] = 2;

    cout << Array[0][8] << endl;
    system("pause");
    return(0);
}

      

+3


source to share


2 answers


It looks to me like the array assigned this type:

An element in a two-dimensional array is accessed using indices, that is, the row index and the column index of the array. For example:

type arrayName [ x ][ y ];

      

Where type can be any valid C ++ data type and arrayName will be a valid C ++ identifier.



A two-dimensional array can be thought of as a table with x number of rows and y number of columns. A two-dimensional array a containing three rows and four columns can be shown below:

enter image description here

Thus, each element in array a is identified by an element name of the form a [i] [j], where a is the name of the array and i and j are indices that uniquely identify each element in a.

 int val = a[2][3];

      

+1


source


Array of array index [0] [8] is not within the bounds of array int [8] [8]

If you leave this line commented out as shown below, it will still print 2. It may be gaining some garbage value.



//Array[0][8] = 1;

      

0


source







All Articles