Right Click to Search

Saturday, June 19, 2024

If Statement MCQ 4 : Comparison operators/Relational operators


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


Tags / Keywords : |

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates