[英]C and C++ compiler give different messages for the following code, why?
[英]Why does cout and return give different values in the following c++ code?
#include <iostream>
using namespace std;
int fn1 (){
int a = 5;
int b = 6;
cout << (++a > b--)? (a+b):(a-b) ;
a = 5;
b = 6;
return (++a > b--)? (a+b):(a-b);
}
int main (){
cout << fn1();
}
// 输出:01
运算符优先级。
cout << (++a > b--)? (a+b):(a-b);
被解析为:
(cout << (++a > b--))? (a+b):(a-b);
首先评估cout <<
然后是其余的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.