Relational Operator
1. equality
operator (==)
2. not equal
( !=)
3. less
than
4..greater
than
5. less than
equal to
6. greater than
equal to
1. Equality
operator (==)
#include<stdio.h>
int main()
{
int a=5,b=10;
if(a==b)
printf("a and b is equal ");
else
printf("a and b is not equal ");
return 0;
}
2. not equal ( !=)
#include<stdio.h>
int main()
{
int a=5,b=10;
if(a!=b)
printf("a and b is not equal ");
else
printf("a and b is equal ");
return 0;
}
int main()
{
int a=5,b=10;
if(a==b)
printf("a and b is equal ");
else
printf("a and b is not equal ");
return 0;
}
2. not equal ( !=)
#include<stdio.h>
int main()
{
int a=5,b=10;
if(a!=b)
printf("a and b is not equal ");
else
printf("a and b is equal ");
return 0;
}
Output :
a and b is not equal
Logical
Operator
1. Logical AND (&&)
2. Logical OR (||)
3. Logical NOT (!)
Logical AND
#include<stdio.h>
int main()
{
int a=5,b=10;
if(a==10&&a==5)
printf("AND condition satisfy");
else
printf("AND condition not satisfy");
return 0;
}
Output :
AND condition not satisfy
Logical OR (||)
#include<stdio.h>
int main()
{
int a=5,b=10;
if(a==10||a==5)
printf("OR condition satisfy");
else
printf("OR condition not satisfy");
return 0;
}
Output:
OR condition satisfy
3. Logical NOT (!)
#include<stdio.h>
int main()
{
int a=5,b=10;
if(!a)
printf("Yes");
else
printf("No");
return 0;
}
Output :
No
MCQ
1. The result of a Relational operation is always
MCQ
1. The result of a Relational operation is always
A) either True or False
B) is less than or is more than
C) is equal or less or more
D) All of the above
2 23 f i = 8 and j = 5 are two integers, then the value of (i>0) || (j < 5) is
2 23 f i = 8 and j = 5 are two integers, then the value of (i>0) || (j < 5) is
A) -5
B) 1
C) 0
D) 5
3 What would be value of j after the following is executed?
3 What would be value of j after the following is executed?
k=17; j=6; if (k < 10) j=8; j=j+1; j=j+2;
A) 8
B) 9
C) 7
D) 10
4 Which of the following is not a valid relational operator?
4 Which of the following is not a valid relational operator?
A) <
B) =
C) >=
D) <=
5 What will be the output of the following ‘C’ program
main()
{
int a=5;
float b=5.0;
if(a==b)
printf(“a and b are equal”);
else
printf(“a and b are different”);
}
}
A) a and b are equal
B) B) a and b are different
C) C) Error
D) D) None of the above
6 What will be the output of the following ‘C’ program?
main()
{
int a=1;
int a=1;
int b=5;
if(a=5||b>10)
printf(“I will certainly pass”);
else
printf(“I am not so sure about the result”); }
A) I will certainly pass
B) I am not so sure about the result
C) Error
D) None of the above
7 The && and | | operators
A) compare two numeric values
B) combine two numeric values
C) compare two boolean values
D) None of the above
8 What is the output of the following program segment?
#include main()
{
int i=10, m=10;
clrscr();
printf(“%d”, i>m?i*i:m/m,20);
getch();
}
A) 20
B) 1
C) 120
D) 100 20
9 The && and || operators
9 The && and || operators
A) compare two numeric values
B) combine two numeric values
C) compare two Boolean values
D) combine two Boolean values
10 The value of variable x after executing the following code will be: val = -200; x = (val >= 0 ) ? val : -val
A) 0
B) 200
C) –200
D) 1
True/False
1. Every ‘if’ statement must also include ‘else’.
22. The expression on the right hand side of && and || operators does not get evaluated if the left hand side determines the outcome.
11 What is the value of r after this code is executed? r=2; k=8; if (r>3 || k>6 && r 10) r=50; else r=9
A) 9
B) 2
C) 6
D) 50
True/False
1. Every ‘if’ statement must also include ‘else’.
22. The expression on the right hand side of && and || operators does not get evaluated if the left hand side determines the outcome.
No comments:
Post a Comment