Relational operators let you compare values. Is one thing bigger than another? Are they equal? These operators give you a 1 (true) or 0 (false). They are the backbone of decision-making in C.
The Comparison Operators
==— equal to (do not confuse with=, which assigns)!=— not equal to<— less than>— greater than<=— less than or equal to>=— greater than or equal to
The double equals == trips up beginners constantly. A single = assigns a value. Double == checks equality. Use the wrong one and your program will behave strangely.
#include
int main() {
int x = 10;
int y = 20;
printf("x == y: %d\n", x == y);
printf("x != y: %d\n", x != y);
printf("x < y: %d\n", x < y);
printf("x > y: %d\n", x > y);
printf("x <= y: %d\n", x <= y);
printf("x >= y: %d\n", x >= y);
return 0;
}
Try it Yourself →