Basic Operators in C Programming Language (Cont
Basic Operators in C Programming Language (Cont
(Cont)
Relational Operators or Comparison Operators
These are used for comparison of the values of
two operands.
#include <stdio.h>
int main()
{
int x=5;
int y=3;
if (x==y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // return false because 5 is not equal to 3
}
}
Example1: != (Not equal)
#include <stdio.h>
int main()
{
int x=5;
int y=3;
if (x!=y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // return true because 5 is not equal to 3
}
}
Example1:>(Greater than )
#include <stdio.h>
int main()
{
int x=5;
int y=3;
if (x>y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns true because 5 is greater than 3
}
}
Example1:<(Less than )
#include <stdio.h>
int main()
{
int x=5;
int y=3;
if (x<y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns false because 5 is not less than 3
}
}
Example1: >=(Greater than or equal to)
#include <stdio.h>
int main()
{
int x=5;
int y=3;
if (x>=y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns true because 5 is greater, or equal, to 3
}
}
Example1:<=(Less than or equal to)
#include <stdio.h>
int main()
{
int x=5;
int y=3;
if (x<=y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns false because 5 is neither less than or equal to 3
}
}
Logical Operators
Logical operators are used to determine the logic
between variables or values.
Example1: && (Logical and)
#include <stdio.h>
int main()
{
int x=5;
}
Example1: || (Logical or)
#include <stdio.h>
int main()
{
int x=5;
}
Example1: !(Logical not)
#include <stdio.h>
int main()
{
int x=5;