vendredi 26 octobre 2018

Comparing three integer variables in one if condition (C) [duplicate]

This question already has an answer here:

Recently I'm doing a C programming quiz to prepare for my final examination which will be held next week. As I go through the questions, there's a question which is quite suspicious that can be found in Quiz 4:

#include <stdio.h>

int main()
{
   int a=15, b=10,c=5;
   if(a>b>c){
    printf("True");
   }
   else {
    printf("False");
   }
   return 0;
}

As I revised on Operators in C, I can't find a single statement that allows three integers to be compared in one condition of if-else, while loop, etc. The answer should be False and I've checked it using Codeblocks 17.12.

So, my question is: is this type of condition allowed to be used in C? AFAIK, to compare three integers, one should use the logical AND operator (&&) i.e. if(a>b && b>c)

Thanks.

Aucun commentaire:

Enregistrer un commentaire