There is no bool type in C language

2020年3月2日 64点热度 0人点赞 2条评论
内容目录

C language does not have a bool type, but many places require true and false. How to solve this?
In C language, 1 and 0, or non-zero and 0, are generally used to represent true and false.

For example:

int a = 6666;
int b = 161616;
printf("%s", a & b ? "true" : "false");

The result of a & b is a number, and as long as it is greater than 0 or less than 0, it is considered true.
Moreover, in C#, the ?: operator requires the left condition to be a bool; it cannot be a number.

You can find examples of using boolean types for judgment in C and C# at https://www.whuanle.cn/archives/737.

痴者工良

高级程序员劝退师

文章评论