C Booleans

Uses integers to represent boolean values.
  1. 0 typically represents false
  2. Any non-zero value represents true
The <stdbool.h> header is used to introduce the boolean type (bool) and the constants true and false.

Example

#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;
}

Using operators

Example

#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;
}

Comparing Varables

Example

#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;
}

Quick Recap - Topics Covered

C Booleans
Using Operators

Practice With Examples in Compilers

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.

Example js

Example 1 Example 2 Example 3 Example 4 Example 5


Quiz


FEEDBACK

Rating


Message