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
- 20
- 1
- 10
- 0
num3 = num1 > 2 + num2!=3;
Steps :
- Always Count How many Operators are there in the Expression . [ Here Operators = 4 ].
- Click Here to Decide Which Operator has Highest Priority.
- Create Table and Decide Priority bu t make sure that expression does not contain Parenthesis .
Operator | Priority Rank |
+ | 1 |
> | 2 |
!= | 3 |
= | 4 |
- 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]