If Statement MCQ 4 : Comparison operators/Relational operators

Before Solving this Question You Should know : Operator Precedence and Priority Basic

Problem Statement 13 : Comparison operators/Relational operators

#include<stdio.h>
void main()
{
int num1=10,num2=20,num3;
num3 = num1 > num2 && num2 > num1;
printf("%d",num3);
}

Options : Guess the Output

  1. 20
  2. 1
  3. 10
  4. 0



num3 = num1 > num2 && num2 > num1;

How ? Why ?

  1. Above Expression Contain 3 Unique Operators [ > , && ,= ]
  2. Out Of them , Relational Operator has Highest Priority and .Assignment Operator [=] has Lowest Priority .
  3. So num1 > num2 will be executed First. Steps of Evaluation are as Follow -
Step 1 : num3 = num1 > num2 && num2 > num1
Step 2 : num3 = 0 && num2 > num1
Step 3 : num3 = 0 && 1
Step 4 : num3 = 0