C语言布尔值如何表示
在C语言中,布尔值通经常使用一个整数来表示,0表示假,非零值表示真。C99标准引入了stdbool.h头文件,可使用bool类型来表示布尔值,true表示真,false表示假。stdbool.h头文件中定义了true和false的宏,可以直接使用。例如:
#include <stdbool.h>
int main() {
    bool flag = true;
    
    if (flag) {
        printf("布尔值为真
");
    } else {
        printf("布尔值为假
");
    }
    
    return 0;
}
                        
   
                TOP