Relational Operators in C programming language return true(non-zero number) or false(0) value. They operate on 2 operands.
Page Contents
== equality operator.
!= inequality operator.
> greater than operator.
< less than operator.
>= greater than or equal to operator.
<= less than or equal to operator.
#include < stdio.h > int main() { //Relational Operators int a = 10, b = 10; int temp; temp = (a == b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 1
#include < stdio.h > int main() { //Relational Operators int a = 10, b = 20; int temp; temp = (a == b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 0
#include < stdio.h > int main() { //Relational Operators int a = 10, b = 10; int temp; temp = (a != b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 0
#include < stdio.h > int main() { //Relational Operators int a = 10, b = 20; int temp; temp = (a != b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 1
#include < stdio.h > int main() { //Relational Operators int a = 20, b = 10; int temp; temp = (a > b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 1
#include < stdio.h > int main() { //Relational Operators int a = 20, b = 10; int temp; temp = (a < b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 0
#include < stdio.h > int main() { //Relational Operators int a = 20, b = 10; int temp; temp = (a >= b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 1
#include < stdio.h > int main() { //Relational Operators int a = 20, b = 10; int temp; temp = (a <= b); printf("value of temp is %d\n", temp); return 0; }
Output:
value of temp is 0
In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program
Relational Operators In C
Note: = is assignment operator. == is equality operator.
This video was produced as building block for our simple calculator application.
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert