c - "if"的 gnu C 条件

标签 c gnu

例如,我们得到了 if(expression) {...}。我们都知道如果 expression 为真,它会执行大括号中的行。但是 C 中的“True”是什么? 那 != 0 是否如我所想的那样是真的?

谢谢

最佳答案

这是标准的内容。

§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.

关于c - "if"的 gnu C 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5024665/

相关文章:

c - 这个程序中的posix_memalign是什么意思?

c - 海湾合作委员会不工作

linux - 不支持配置 arm-unknown-elf - ARM 工具链

c - GNU C 扩展文档 : where is it?

c - c中的二分查找-必须找出键的所有数组位置

c - Win32 公共(public)控件初始化会破坏自定义控件吗?

linux - 并排差异 (-y) : how to hide the reverse-video ^M (at end-of-line)?

regex - 从第一个点之前的子字符串中删除双引号

c - 来自 makedepend 的警告

c - 如何在不使用递归的情况下从(无论用户输入的整数)打印到 0 然后返回到整数? (计算类作业)