[英]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.