Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 条件运算符的问题 #包括 int main() { printf(“%d\n”,4?:8); }_C_Gcc_Ternary Operator - Fatal编程技术网

C 条件运算符的问题 #包括 int main() { printf(“%d\n”,4?:8); }

C 条件运算符的问题 #包括 int main() { printf(“%d\n”,4?:8); },c,gcc,ternary-operator,C,Gcc,Ternary Operator,根据C标准,这个程序是无效的,因为它在?和:之间缺少一个表达式。但有趣的是,当我编译代码时,它正在打印4。为什么它会打印4,而不是显示任何编译错误呢分机 #include<stdio.h> int main() { printf("%d\n", 4 ?: 8); } 相当于 x ? : y 有关详细信息,请参见。+1也可链接gcc文档。 x ? x : y

根据C标准,这个程序是无效的,因为它在
之间缺少一个表达式。但有趣的是,当我编译代码时,它正在打印
4
。为什么它会打印
4
,而不是显示任何编译错误呢分机

#include<stdio.h>
int main()
{
  printf("%d\n", 4 ?: 8);
}
相当于

x ? : y

有关详细信息,请参见。

+1也可链接gcc文档。
x ? x : y