Prev Next
Relational operators in C:
Relational operators are used to find the relation between two variables. i.e. to compare the values of two variables in a C program.
Operators

Example/Description

>

x > y (x is greater than y)

<

x < y (x is less than y)

>=

x >= y (x is greater than or equal to y)

<=

x <= y (x is less than or equal to y)

==

x == y (x is equal to y)

!=

x != y (x is not equal to y)

Example program for relational operators in C:
 In this program, relational operator (==) is used to compare 2 values whether they are equal are not.
 If both values are equal, output is displayed as ” values are equal”. Else, output is displayed as “values are not equal”.
 Note : double equal sign (==) should be used to compare 2 values. We should not single equal sign (=).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
#include <stdio.h> int main() { int m=40,n=20; if (m == n) { printf("m and n are equal"); } else { printf("m and n are not equal"); } } 
Output:
m and n are not equal

Continue on types of C operators:
Click on each operator name below for detailed description and example programs.
Types of Operators

Description

Arithmetic_operators  These are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus 
Assignment_operators  These are used to assign the values for the variables in C programs. 
These operators are used to compare the value of two variables.


These operators are used to perform logical operations on the given two variables.


These operators are used to perform bit operations on given two variables.


Conditional operators return one value if condition is true and returns another value is condition is false.


These operators are used to either increase or decrease the value of the variable by one.


&, *, sizeof( ) and ternary operators.

Prev Next
Ask your questions or clarify your/others doubts from,