gnu C condition of "if"
we got if(expression) {...}
for example. We all know if expression is true, it will execute lines in开发者_Python百科 braces. But what is "True" in C?
Is that != 0 means true as I think?
Thank you
Here is what the standard has to say.
§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.
Any none-zero result tests as true.
Yes, true is not-null in C and C++.
精彩评论