code is perfectly correct |
No, it is not!
Line 9: the
j
is not initialized.
Undefined behaviour.
Line 10 has
direct assignment. Since C++11 it has allowed the braces, {}.
That is why line 10 is ok.
https://en.cppreference.com/w/cpp/language/operator_assignment
Line 14 should compare two
characters.
The
'G'
is a character.
The
{'G'}
is not a character. It is an
array that contains one character.
There is no
!=
that compares two plain arrays.
Remember: There is no element at index N in an array that has N elements.
Your matrix has 6 columns. Columns 0, 1, 2, 3, 4, and 5. The 6 is not a valid index.
However, the
array[2][6]
is technically a character. The
first character of
fourth row.
It should be written:
array[3][0]
I bet that was not your intention.