How is the boolean type defined in C language?

In the C language, there are no predefined keywords for the boolean type. Typically, int type can be used to represent boolean type, and constants can be defined to represent true and false.

For example:

#include <stdbool.h>

int main() {
    bool isTrue = true; // 布尔类型变量定义为true
    bool isFalse = false; // 布尔类型变量定义为false

    if (isTrue) {
        printf("isTrue is true.\n");
    } else {
        printf("isTrue is false.\n");
    }

    if (isFalse) {
        printf("isFalse is true.\n");
    } else {
        printf("isFalse is false.\n");
    }

    return 0;
}

Output results:

isTrue is true.
isFalse is false.

In the above example, the boolean type is defined using the header file stdbool.h. The variable isTrue is true, and the variable isFalse is false. Output the corresponding information based on the result of the conditional statement.

bannerAds