hallo
i am new to C++
and i start learning array, and i played with it
i made a code that insert values to 2D array (arr[x][y])
the input is: 1 2 3 4 5 6 7 8 9
the output does show correctly
but at the end of the code when i check what value there are
in the 0,2 or 1,2 index i see a wrong values..
this is the code:
index 0,2 should show me the value 3 but instead it show me 4Code:#include <iostream> using namespace std; int main(void){ int arr[2][2]; for (int x = 0; x<=2; x++){ for (int y = 0; y<=2; y++){ cin >> arr[x][y]; cout << arr[x][y] << endl; } } cout << "the arr value is: " << arr[0][2] << endl; }
index 1,2 should show me the value 6 but instead it show me 7
the rest of the index show a correct values.
please help me understand what is wrong here
thank you