Uses integers to represent boolean values.
The <stdbool.h> header is used to introduce the boolean type (bool) and the constants true and false.
#include <stdio.h>
#include <stdbool.h>
int main() {
bool isTrue = true;
bool isFalse = false;
if (isTrue) {
printf("This condition is true.\n");
} else {
printf("This condition is false.\n");
}
if (!isFalse) {
printf("This condition is also true.\n");
} else {
printf("This condition is false.\n");
}
return 0;
}
#include <stdio.h>
int main() {
int a = 5, b = 3;
int isEqual = (a == b); // 0 (false)
int isNotEqual = (a != b); // 1 (true)
if (isEqual) {
printf("The numbers are equal\n");
} else {
printf("The numbers are not equal\n");
}
if (isNotEqual) {
printf("The numbers are not equal\n");
} else {
printf("The numbers are equal\n");
}
return 0;
}
#include <stdio.h>
int main() {
int a = 10, b = 5;
int result;
// Comparison: a > b
result = (a > b);
if (result) {
printf("a is greater than b\n");
} else {
printf("a is not greater than b\n");
}
// Comparison: a == b
result = (a == b);
if (result) {
printf("a is equal to b\n");
} else {
printf("a is not equal to b\n");
}
return 0;
}
The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.