How are boolean values represented in C?

QuestionsQuestions8 SkillsProUse Basic Operators In CAug, 07 2025
0178

In C, boolean values are typically represented using the stdbool.h header, which defines the bool type. The bool type can hold two values: true and false. Here’s how you can use boolean values in C:

#include <stdio.h>
#include <stdbool.h>

int main() {
    bool isTrue = true;
    bool isFalse = false;

    if (isTrue) {
        printf("This is true!\n");
    }

    if (!isFalse) {
        printf("This is false!\n");
    }

    return 0;
}

In this example:

  • true is defined as 1, and false is defined as 0.
  • The stdbool.h header allows you to use the bool type and the true and false constants.

0 Comments

no data
Be the first to share your comment!