You have allocated a 3x3 array but you are using it as if it were a 4x4 array.
If you want a 4x4 array you should change n to 4, and if you don't want to rely on non-standard compiler extensions you also need to make it a constant.
constint n = 4;
You also need to change i <= n to i < n (same for j).
In C, indices go from 0 to one less than the size. And if you want the size to be 4 by 4, then N must be 4, not 3. And N should be const (in standard C++).
BTW, those //for, //main, etc comments are just clutter.