C89标准中没有定义布尔类型;

C99中增加了_Bool类型。
_Bool型变量实际上只是一个整数类型,
但是,_Bool只能被赋值为0或1,凡是不为0的整数都被转变为1,
如:

#include<stdio.h>
int main(int argc,char *argv[])
{
    _Bool flg;
    flg=5;
    printf("%d\n",flg);
    return 0;
}

输出:1


C99还提供了一个头文件<stdbool.h>,该头文件提供了bool宏来代替_Bool,

还提供了true和false代替1和0,如:

#include <stdio.h>
#include <stdbool.h>
int main(void)
{
    bool flg;
    flg=true;
    printf("%d\n",flg);
    flg=false;
    printf("%d\n",flg);
    return 0;
}

输出:

1
0


 

测试环境:
操作系统:Windows7(32位)
编译软件:Code::Blocks 10.05

相关文章:

  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-04-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2021-06-23
  • 2021-07-16
  • 2021-06-13
  • 2021-07-03
  • 2022-12-23
  • 2021-09-17
相关资源
相似解决方案