C语言 在 c 中,在 bool 中,true == 1 和 false == 0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40009029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:30:05  来源:igfitidea点击:

In c, in bool, true == 1 and false == 0?

cboolean

提问by Piotrek Karpowicz

Just to clarify I found similar answer but for C++, I'm kinda new to coding so I'm not sure whether it applies to C as well.

只是为了澄清我发现了类似的答案,但是对于 C++,我对编码有点陌生,所以我不确定它是否也适用于 C。

回答by Neil Locketz

More accurately anything that is not 0is true.

更准确地说,任何不是0真的。

So 1is true, but so is 2, 3... etc.

所以1是真实的,但也是如此23...等等。

回答by Eric Lippert

You neglected to say which version of C you are concerned about. Let's assume it's this one:

你忽略了你关心的是哪个版本的 C。让我们假设它是这个:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

As you can see by reading the specification, the standard definitions of trueand falseare 1 and 0, yes.

你可以通过阅读说明书看到,标准的定义truefalse为1和0,是的。

If your question is about a different version of C, or about non-standarddefinitions for trueand false, then ask a more specific question.

如果您的问题是关于 C 的不同版本,或关于and的非标准定义,请提出更具体的问题。truefalse