Array erroneously symmetric in [0][n] and [n][0]

Hello! I'm self-teaching myself C++ and trying to get grips with arrays and have just run into this problem:

The component "array[0][n]" should (presumably?) be different from "array[n][0], so in the code fragment below I'd expect my output to be "22", but instead, it's "23".
Changing "array[0][n]" seems to change "array[n][0]".
Why is this and can anyone suggest how to fix this?

1
2
3
4
5
int matrix1[1][1]; // a 2x2 matrix
  matrix1[1][0]=2;
       cout << matrix1[1][0];
       matrix1[0][1]=3;
       cout << matrix1[1][0];


This only seems to be a problem in the 0th rows and columns (after experimentation with a 3x3 array)...

Any help much appreciated.
First of all you defined array as 1 x 1 matrix:)

Both assignment statements write beyond the array that is there is neither matrix1[1][0] element nor matrix1[0][1] element. Your array has only one element matrix1[0][0].
So it seems the both assignment statements changes the same memory beyond the array.:)
Thank-you for pointing that out - everything works fine now ; )
Topic archived. No new replies allowed.