Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1056962
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: C/C++

2015-12-02 16:08:03

不使用头文件,自己实现bool变量

点击(此处)折叠或打开

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. /*#include <stdbool.h>*/

  5. /*typedef enum {false, true} bool;*/

  6. enum FLAG{
  7.     false,
  8.     true,
  9. };
  10. typedef enum FLAG bool;

  11. int main(int argc, char ** argv)
  12. {
  13.     printf("false=[%d], true=[%d]\n", false, true);
  14.     bool flag = true;
  15.     if(flag == true)
  16.     {
  17.         printf("flag is true![%d]\n", flag);
  18.     }
  19.     else
  20.     {
  21.         printf("flag is false!\n");
  22.     }
  23.     return 0;
  24. }
使用头文件

点击(此处)折叠或打开

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <stdbool.h>

  5. int main()
  6. {
  7.     bool flag1 = true;
  8.     bool flag2 = false;
  9.     
  10.     if(flag1 == true)
  11.     {
  12.         printf("flag1 is true!\n");
  13.     }
  14.     
  15.     if(!flag2)
  16.     {
  17.         printf("flag2 is false!\n");
  18.     }
  19.     return 0;
  20. }

阅读(373) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~