开发者

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

  1. selection-statement:
    if ( expression ) statement
    if ( expression ) statement else statement
    switch ( expression ) statement

§6.8.4.1 The if statement

Constraints

  1. The controlling expression of an if statement shall have scalar type.

Semantics

  1. 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.
  2. 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++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜