0

Hi,

Can I check a two-dimensional array like this ?
The content of the arrays are of type char

matrix[0][0] == matrix[1][1] == matrix[2][2]
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Swemp
0

The short answer is yes, BUT it does not do the obvious thing.

Let me explain a bit. It is the same as:
(assumes that matrix[][] is of type char.)

bool X=  (matrix[1][1]==matrix[2][2]);

bool Ans  = (matrix[0][0] == static_cast<char>(X))

Note that it is VERY unlikely that is what you really want since bool
will only give you char(0) or char(1).

Also that you are using matrix[][] is completely unimportant e.g.

int a(5),b(5),c(5);
if (a==b==c)
  {
     std::cout<<"This is never written"<<std::endl;
  }
else
   {
      std::cout<<"Surprised??"<<std::endl;
   }

hope that helps.

p.s. you need to do (matrix[0][0]==matrix[1][1]) && (matrix[1][1]==matrix[2][2])

0

The short answer is yes, BUT it does not do the obvious thing.

Let me explain a bit. It is the same as:
(assumes that matrix[][] is of type char.)

bool X=  (matrix[1][1]==matrix[2][2]);

bool Ans  = (matrix[0][0] == static_cast<char>(X))

Note that it is VERY unlikely that is what you really want since bool
will only give you char(0) or char(1).

Also that you are using matrix[][] is completely unimportant e.g.

int a(5),b(5),c(5);
if (a==b==c)
  {
     std::cout<<"This is never written"<<std::endl;
  }
else
   {
      std::cout<<"Surprised??"<<std::endl;
   }

hope that helps.

p.s. you need to do (matrix[0][0]==matrix[1][1]) && (matrix[1][1]==matrix[2][2])

Thanks for helping me !
It works !

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.