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
- 20
- 1
- 10
- 0
num3 = num1 > num2 && num2 > num1;
How ? Why ?
- Above Expression Contain 3 Unique Operators [ > , && ,= ]
- Out Of them , Relational Operator has Highest Priority and .Assignment Operator [=] has Lowest Priority .
- 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