If Statement MCQ 5 : Comparison operators/Relational operators

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

Problem Statement 5 : Comparison operators/Relational operators

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

Options : Guess the Output

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



num3 = num1 > 2 + num2!=3;

Steps :

  1. Always Count How many Operators are there in the Expression . [ Here Operators = 4 ].
  2. Click Here to Decide Which Operator has Highest Priority.
  3. Create Table and Decide Priority bu t make sure that expression does not contain Parenthesis .
OperatorPriority Rank
+1
>2
!=3
=4
  1. Addition Operator has Highest Priority so “+” Operation evaluated first.

Steps of Solving Expression :

Step 1 : num3 = num1 > 2 + num2 !=3;
Step 1 : num3 = num1 > 2 + 20 !=3; [Put Value of num2 ]
Step 2 : num3 = num1 > 22 != 3;    [Do Addition ]
Step 3 : num3 = 0 != 3;            [Relational Opr.">"]
Step 4 : num3 = 1;                 [0 != 3 is True]