if 语句如何为真

问题描述 投票:0回答:1

我知道程序的输出是上帝。

if语句为true时的代码是怎么写的?这是布尔计算,我不明白。请有人能详细说明发生了什么吗??

void main()

{

int a=10;

if(!(!a)==!0)

   printf("GOD");

else

   printf("Good");

}
c computer-science
1个回答
0
投票
如果操作数的值为零,则

!
计算结果为
1
,否则计算为
0

如果两个操作数具有相同的值,则

==
计算为
1
,否则计算为
0

!(!a)==!0
!(!10)==!0
!(0)==!0       // 10 is non-zero, so !10 is 0.
!0==!0         // 0 is zero, so !0 is 1.
1==1           // The two values are equal, so 1==1 is 1.
1              // 1 is non-zero, so "then" statement is executed.
© www.soinside.com 2019 - 2024. All rights reserved.