【发布时间】:2013-08-20 11:08:06
【问题描述】:
main()
{
int k = 5;
if(++k <5 && k++/5 || ++k<=8); // how to compiler compile this statement
print f("%d",k);
}
// 这里的答案是 7,但为什么?
【问题讨论】:
-
注意:短路算子是序列点。
-
@ankitdixit:您需要了解 C 和 C++ 中
&&和||的短路行为,因此请随时搜索和阅读。 -
您缺少
main的返回类型 (int)。if与printf无关;它只控制空语句;。 -
当你问为什么输出是这样的时候,解释你的期望也是很好的。而
main()在C++中是非法的,需要拼出返回类型int。
标签: c++ c compiler-construction