代碼:
1 #include <cstdio> 2 #include <iostream> 3 4 using namespace std; 5 6 int main(){ 7 8 int t1,t2; 9 t1 = 2,t2++; 10 cout<<t1<<" "<<t2<<endl; 11 t1 = (5,6); //必須要加括號否則編譯出錯 12 cout<<t1<<endl; 13 14 return 0; 15 }
輸出:
2 1 6
分析:
逗號運算符優先級最低,從左到右執行。
需要注意的是第九行代碼實際上是兩條表達式。