例如,我们得到了 if(expression) {...}
。我们都知道如果 expression 为真,它会执行大括号中的行。但是 C 中的“True”是什么?
那 != 0 是否如我所想的那样是真的?
谢谢
最佳答案
这是标准的内容。
§6.8.4 Selection statements
Syntax
selection-statement:
if ( expression ) statement
if ( expression ) statement else statement
switch ( expression ) statement
§6.8.4.1 The
if
statementConstraints
- The controlling expression of an if statement shall have scalar type.
Semantics
- In both forms, the first substatement is executed if the expression compares unequal to 0. In the else form, the second substatement is executed if the expression compares equal to 0. If the first substatement is reached via a label, the second substatement is not executed.
- An
else
is associated with the lexically nearest preceding if that is allowed by the syntax.
关于c - "if"的 gnu C 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5024665/