哪些数字评估为真和假? [英] Which numbers evaluate to true and false?

查看:65
本文介绍了哪些数字评估为真和假?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得如果(1)评估为真,所有其他数字包括0

评估为假。


但我在哪里可以找到关于这肯定??我已经通过K& R查看了所有

C for dummies书籍和各种其他C编程书籍但无处

有一个关于if语句中的数字的提及评价为。


这是一个什么大秘密?

As I remember if(1) evaluates to true and all other numbers including 0
evaluate to false.

But where do I find out about this for sure?? I have looked through K&R, all
the C for dummies books and various other C programming books but nowhere
there is a mention on what a number in an if statement evaluates to.

Is this some kind of big secret?

推荐答案

几乎。 0评估为false,任何其他数字为true(我不完全

确定浮点数)。


干杯,

Chris


Paminu写道:
Nearly. 0 evaluates to false and any other number to true (I am not completely
sure about floating point).

Cheers,
Chris

Paminu wrote:
我记得如果(1)评估为真,所有其他数字包括0
评估假的。

但我在哪里肯定会发现这个?我已经浏览了K& R,所有的C傻瓜书以及其他各种C编程书籍,但无处都有提及if语句中的数字是什么评价。
<这是一个什么大秘密?
As I remember if(1) evaluates to true and all other numbers including 0
evaluate to false.

But where do I find out about this for sure?? I have looked through K&R, all
the C for dummies books and various other C programming books but nowhere
there is a mention on what a number in an if statement evaluates to.

Is this some kind of big secret?



Paminu写道:
我记得如果(1)评估为true和所有其他数字,包括0
评估为false。

编号如果(1)什么都不是。如果你的意思是


如果(1){

...

}


这对任何东西都没有评价;这是一个声明。


if中的陈述如果测试

表达式求值为非零值,则将执行分支。否则,否则是指否则。分支

将被执行,如果有的话。

if(x){

...

}



相同如果(x!= 0){

...

}


所以你的陈述实际上是倒退:0是假 (松散地说b $ b说话,因为C没有合适的布尔类型)并且任何非零
值都是真。但是假和真实的不存在实际价值。一个

运算符,如!=将产生0或1,所以我们可以调用那些

" false"和真实,只要我们记住C实际上有点比这更自由了。

但我在哪里可以找到这个肯定的??我已经浏览了K& R,所有的C傻瓜书以及其他各种C编程书籍,但无处都有提及if语句中的数字是什么评价。

可能是因为你没有正确阅读它们。我读过的所有书都能解决这个问题,但不完全符合你的解释方式。

是这是一个什么样的大秘密?
As I remember if(1) evaluates to true and all other numbers including 0
evaluate to false.
No. if(1) is nothing. If you meant something like

if (1) {
...
}

That doesn''t evaluate to anything; it''s a statement.

The statements in the "if" branch will be executed if the test
expression evaluates to a non-zero value. Otherwise, the "else" branch
will be executed, if there is one.
if (x) {
...
}
is the same as
if (x != 0) {
...
}

So your statement actually gets it backwards: 0 is "false" (loosely
speaking, since C doesn''t have a proper boolean type) and any non-zero
value is "true". But "false" and "true" don''t exist as actual values. An
operator like != will yield either 0 or 1, so we could call those
"false" and "true", as long as we keep in mind that C is actually a bit
more liberal than that.
But where do I find out about this for sure?? I have looked through K&R, all
the C for dummies books and various other C programming books but nowhere
there is a mention on what a number in an if statement evaluates to.
Probably because you''re not reading them quite right. All books I''ve
read do address this issue, but not exactly in the way you''re
interpreting it.
Is this some kind of big secret?




是的:C没有布尔类型。但我不会称它为大。 :-)


S.



Yes: C has no boolean type. But I wouldn''t call it "big". :-)

S.


Paminu< ja ****** @ asd.com>写道:
Paminu <ja******@asd.com> wrote:
我记得如果(1)评估为真,所有其他数字包括0
评估为假。


No.比较等于0的表达式,包括NULL指针,是
" false"。所有其他人都是真实的。

但我在哪里可以找到这个肯定的?我已经浏览了K& R,所有的C傻瓜书以及其他各种C编程书籍,但无处都有提及if语句中的数字是什么评价。
As I remember if(1) evaluates to true and all other numbers including 0
evaluate to false.
No. Expressions that compare equal to 0, including NULL pointers, are
"false". All others are "true".
But where do I find out about this for sure?? I have looked through K&R, all
the C for dummies books and various other C programming books but nowhere
there is a mention on what a number in an if statement evaluates to.




这是我的K& R 2副本的第223页。


-

Christopher Benson- Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



It is on page 223 of my copy of K&R 2.

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


这篇关于哪些数字评估为真和假?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆