Course contentsShow
← C
Lesson 164 of 1,2193. Operators and ExpressionsFree lesson

Boolean result of comparisons

Boolean result of comparisons

What you'll learn: How C represents the "truth" of a comparison using integers.

The Language of True and False

When you ask a question in English like "Is 5 greater than 3?", the answer is a simple "Yes." In programming, we call these Yes/No answers Boolean values (True or False). However, C handles these answers in a way that often surprises beginners: it uses plain old numbers.

In C, there is no built-in "True" or "False" word in the core language. Instead, C follows a very simple rule:

  • 0 represents False.
  • 1 (or any non-zero number) represents True.

When you use a relational operator—like > (greater than) or == (equal to)—the computer performs the math and then spits out a 1 if the statement is a fact, or a 0 if it is a lie.

Seeing the Result

Think of a relational operator as a tiny judge. If you hand the judge the expression 10 > 5, the judge evaluates it and hands you back the number 1. If you hand the judge 10 < 5, the judge hands you back a 0.

Because these results are just integers, you can actually store them in a variable or print them out directly using %d.

#include <stdio.h>

int main() {
    int isGreater = (10 > 5);  // Is 10 greater than 5? Yes.
    int isSmaller = (10 < 5);  // Is 10 smaller than 5? No.
    int isEqual = (10 == 10);  // Is 10 equal to 10? Yes.

    printf("Result of 10 > 5: %d\n", isGreater); // Prints 1
    printf("Result of 10 < 5: %d\n", isSmaller); // Prints 0
    printf("Result of 10 == 10: %d\n", isEqual); // Prints 1

    return 0;
}

Why This Matters

This "Zero vs. Non-Zero" logic is the heartbeat of C programming. Later, when you learn to make decisions using if statements, you’ll realize the computer isn't looking for the word "True." It is simply checking if the result of your comparison is something other than zero.

If you ever get confused about whether a comparison worked, remember that you can always print the result. If you see a 1, the light is green; if you see a 0, the light is red.

Key takeaway

In C, a comparison isn't just an idea—it is an expression that evaluates to the integer 1 for true or 0 for false.