if(-1)返回true [英] if (-1) returns true
问题描述
我遇到了这个C代码我想了解等等它看起来像
这个:
if(-1)etc
这让我想知道结果会是什么......是真还是假?
在C和Delphi中
False定义为零。
True定义为非零。
I发现这有点怪异,因为虚假和消极,真实和积极似乎更加直观。
想想一个向士兵提出问题的中尉,士兵将
回复:
否定如果不是这样的话。
" Affirmitive"如果它是真的。
因此这不是更直观吗?:
假定义为负数或零。
真正定义为正面。
再见,
Skybuck。
Hi,
I came across this C code which I wanted to understand etc it looked like
this:
if (-1) etc
It made me wonder what the result would be... true or false ?
In C and Delphi
False is defined as zero.
True is defined as non zero.
I find this a bit weird since false and negative and true and positive seem
more intuitive.
Think of a lieutenant who asks a question to a soldier, the soldier will
reply:
"Negative" if it''s not true.
"Affirmitive" if it''s true.
Therefore wouldn''t this be more intuitive ?:
False defined as negative or zero.
True defined as positive.
Bye,
Skybuck.
推荐答案
Skybuck Flying写道:
Skybuck Flying wrote:
因此这不是更直观吗?:
错误定义为负数或零。
真正定义为正面。
Therefore wouldn''t this be more intuitive ?:
False defined as negative or zero.
True defined as positive.
你在哪里学习编程?
-
jc
从电子邮件中移除-not
Where did you learn programming?
--
jc
Remove the -not from email
顺便说一句,在此上下文中的否定并不意味着数字< 0但是
下降。
By the way, negative in this context doesnt mean a number < 0 but
declining.
2005年3月2日星期三11:05:56 +0100,Skybuck Flying
< no **** @ hotmail.com>写道:
On Wed, 2 Mar 2005 11:05:56 +0100, "Skybuck Flying"
<no****@hotmail.com> wrote:
我遇到了这个我想要了解的C代码等等它看起来像
这个:
if(-1)etc
这让我想知道结果会是什么......是真是假?
在C和Delphi中
False定义为零。
True定义为非零。
Hi,
I came across this C code which I wanted to understand etc it looked like
this:
if (-1) etc
It made me wonder what the result would be... true or false ?
In C and Delphi
False is defined as zero.
True is defined as non zero.
尝试这个小小的演示: -
程序TForm1.Button1Click(发件人:TObject);
开始
案例LongBool(2)
True:ShowMessage(' '真'');
错误:ShowMessage(''错'');
其他ShowMessage(''哎呀 - Bad LongBool'');
结束;
案例布尔值(2)
True:ShowMessage(''True'');
错误:ShowMessage(''False'');
Else ShowMessage(''糟糕 - 坏布尔'');
结束;
如果LongBool(2)那么
ShowMessage(''但这可行for LongBool'');
如果是布尔值(2)那么
ShowMessage(''这适用于布尔'');
ShowMessage(''这就是为什么这是非常不明智的''
+''以明显的方式测试True''
+ #13''虽然,有时也会这样。 :-)''
)
结束;
Try this little demo :-
procedure TForm1.Button1Click(Sender: TObject);
begin
Case LongBool( 2 ) Of
True : ShowMessage( ''True'' );
False : ShowMessage( ''False'' );
Else ShowMessage( ''Oops - Bad LongBool'' );
End;
Case Boolean( 2 ) Of
True : ShowMessage( ''True'' );
False : ShowMessage( ''False'' );
Else ShowMessage( ''Oops - Bad Boolean'' );
End;
If LongBool( 2 ) Then
ShowMessage( ''Yet this works for LongBool'' );
If Boolean( 2 ) Then
ShowMessage( ''And this works for Boolean'' );
ShowMessage( ''Which is why it is very unwise''
+'' to EXPLICITLY test for "True"''
+#13''Although, sometimes one does. :-)''
)
end;
这篇关于if(-1)返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!