C语言使用#define
示例
C中的所有版本,将有效地治疗以外的任何整数值0作为true比较运营商和整数值0的false。如果您没有C99_Bool或bool从C99开始可用,则可以使用#define宏在C中模拟布尔数据类型,并且您仍然可能会在旧版代码中找到这种情况。
#include <stdio.h>
#define bool int
#define true 1
#define false 0
int main(void) {
bool x = true; /* Equivalent to int x = 1; */
bool y = false; /* Equivalent to int y = 0; */
if (x) /* Functionally equivalent to if (x != 0) or if (x != false) */
{
puts("这将打印!");
}
if (!y) /* Functionally equivalent to if (y == 0) or if (y == false) */
{
puts("这也将打印!");
}
}请勿在新代码中引入此内容,因为这些宏的定义可能与的现代用法冲突<stdbool.h>。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短