C uses integers for truth values: 0 is false, anything else is true. Include <stdbool.h> to use bool, true and false.
if (cond) { } else if (cond2) { } else { }- Ternary:
max = (a > b) ? a : b;
Make decisions in C.
✍️ 2 exercises in this lessonC uses integers for truth values: 0 is false, anything else is true. Include <stdbool.h> to use bool, true and false.
if (cond) { } else if (cond2) { } else { }max = (a > b) ? a : b;Mastering C Booleans & If...Else helps you write clean and reliable C code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
#include <stdio.h>
#include <stdbool.h>
int main() {
int temp = 31;
bool isSunny = true;
if (temp > 35) {
printf("Very hot\n");
} else if (temp > 25) {
printf("Warm\n");
} else {
printf("Cool\n");
}
if (isSunny) printf("Take sunglasses\n");
int a = 8, b = 12;
printf("Max: %d\n", a > b ? a : b);
return 0;
}
Warm Take sunglasses Max: 12
Check what you learned in “C Booleans & If...Else”.
Include the header that defines bool, true and false.
#include <>
In C, which value is false?
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services