In C Language, conditional operators, also known as relational operators, are used to compare values and form logical conditions.
They evaluate to either true or false, which are represented by integer values 1 and 0, respectively.
Here are the conditionals operators in C:
Checks if two operands are equal. If they are, the condition becomes true.
Output: a is not equal to b
#include <stdio.h> int main() { int a = 10; int b = 20; // Equal to (==) if (a == b) { printf("a is equal to b\n"); } else { printf("a is not equal to b\n"); } return 0; }
#include <stdio.h> int main() { int a = 10; int b = 20; // Not equal to (!=) if (a != b) { printf("a is not equal to b\n"); } else { printf("a is equal to b\n"); } return 0; }
Output: a is not equal to b
#include <stdio.h> int main() { int a = 10; int b = 20; // Greater than (>) if (a > b) { printf("a is greater than b\n"); } else { printf("a is not greater than b\n"); } return 0; }
Output: a is not greater than b
#include <stdio.h> int main() { int a = 10; int b = 20; // Less than (<) if (a < b) { printf("a is less than b\n"); } else { printf("a is not less than b\n"); } return 0; }
#include <stdio.h> int main() { int a = 10; int b = 20; // Greater than or equal to (>=) if (a >= b) { printf("a is greater than or equal to b\n"); } else { printf("a is less than b\n"); } return 0; }
Output: a is less than b
#include <stdio.h> int main() { int a = 10; int b = 20; // Less than or equal to (<=) if (a <= b) { printf("a is less than or equal to b\n"); } else { printf("a is greater than b\n"); } return 0; }
Output: a is less than b
Output: a is less than or equal to b
Checks if two operands are not equal. If they are not, the condition becomes true.
Checks if the left operand is greater than the right operand. If it is, the condition becomes true.
Checks if the left operand is less than the right operand. If it is, the condition becomes true.
Checks if the left operand is greater than or equal to the right operand. If it is, the condition becomes true.
Checks if the left operand is less than or equal to the right operand. If it is, the condition becomes true.