Relational and Logical
Comparisons and &&, ||.
Comparing Values
Relational operators compare two values and produce a truth value: 1 for true and 0 for false.
<less than>greater than<=less or equal>=greater or equal
#include <stdio.h>
int main(void) {
printf("3 < 5 = %d\n", 3 < 5);
printf("3 > 5 = %d\n", 3 > 5);
return 0;
}Equality and Inequality
Use == to test equality and != to test inequality. Do not confuse == with the assignment operator =.
#include <stdio.h>
int main(void) {
int a = 4, b = 4;
printf("a == b = %d\n", a == b);
printf("a != b = %d\n", a != b);
return 0;
}All lessons in this course
- Arithmetic Operators
- Relational and Logical
- Assignment and Increment
- Operator Precedence