Wednesday, 28 August 2013

Relational Operator | C Programming Language PDF



Relational Operator: 

These are the operators used to Compare arithmetic, logical and character expressions.the value of a relational express is either one or zero .it is 1 if one is the specified relation is true and zero if it is false
For eg:
10 < 20 is true     20<10 is false

The relational operators in C are: 
  Operator       Meaning
     <              is less than
     < =           is less than or equal to
     >              is greater than or equal to
     > =           is greater than or equal to
     = =           is equal to
     ! =            is not equal to

Output:
 Condition : Return values
 10! = 10  : 0
 10 = = 10 : 1
 10> = 10  : 1
 10! = 9   : 1

Program:
WAP to illustrate the use of Logical Operators
void main ( )
{ clrscr ( );
printf(“In 5>3 && 5<10   : %3d”, 5>3&&5<10);
printf(“ In 8<5 || 5= =5 : % 3d”, 8<5 || 5= =5);
printf(“In !(8 = =8)     : %3d”, !(8= =8) ;
}

Output:
5>3 && 5<10   : 1
8<5 || 5= =5  : 1
!(8 = =8)     : 0

Program:
WAP to show the effect of increment and decrement operators
main ( )
{
int x = 10, y = 20, z, a ;
z= x * y ++;
a = x * y ;
printf(“ %d % d\n”, z,a);
z = x * ++y;
a = x * y;
printf(“ %d %d\n”, z, a);
printf(“ ++ x = %d, x++=%d”, ++x, x++);
}

Output:
200 210
220 220
12  10

0 comments:

Post a Comment

 

C Programming Language Interview Questions and Answers Tutorial for beginners. Copyright 2013 All Rights Reserved