Relational Operators in C programming language return true(non-zero number) or false(0) value. They operate on 2 operands.
Relational Operators
== equality operator.
!= inequality operator.
> greater than operator.
< less than operator.
>= greater than or equal to operator.
<= less than or equal to operator.
== equality 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
!= inequality 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 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
> operator
#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
< operator
#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
>= operator
#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
<= operator
#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
Scanf(): For user input
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
[youtube https://www.youtube.com/watch?v=8wlJ4bo110Y]
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