首页 文章

C99布尔数据类型?

提问于
浏览
81

什么是C99布尔数据类型以及如何使用它?

2 回答

  • 102

    包括<stdbool.h> Headers

    #include <stdbool.h>
    
    int main(void){
      bool b = false;
    }
    

    truefalse 分别扩展为 10 .

    7.16 Boolean type and values < stdbool.h >

    1 Headers <stdbool.h>定义了四个宏 . 2宏bool扩展为_Bool . 3其余三个宏适用于#if预处理指令 . 它们是真的:扩展为整数常量1,false:扩展为整数常量0,__ bool_true_false_are_defined扩展为整数常量1. 4尽管有7.1.3的规定,程序可能不完整,可能随后重新定义宏bool,true和false .

  • 42

    请查看DaniWeb上找到的相关主题的答案 .

    提取并引用此处以方便参考: -


    _992_在c99中使用新关键字

    _Bool:C99的布尔类型 . 只有在维护已经为bool,true或false定义宏的遗留代码时,才建议直接使用_Bool . 否则,这些宏在<stdbool.h>标头中标准化 . 包括那个 Headers ,你可以像在C中一样使用bool .

    #include <stdio.h>
    #include <stdbool.h>
    
    int main ( void )
    {
      bool b = true;
    
      if ( b )
        printf ( "Yes\n" );
      else
        printf ( "No\n" );
    
      return 0;
    }
    

相关问题