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]

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])

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 !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.