内容目录
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.
文章评论