复合表达式

复合表达式

如 a = b = c = 0 这样的表达式称为复合表达式。允许复合表达式存在的理由是:

(1) 书写简洁;

(2)可以提高编译效率。但要防止滥用复合表达式。

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     int x,y;
 7     cout<<"x=";
 8     cin>>x;
 9     if (x<=0) {            //满足条件执行
10        y=2*x; 
11        cout<<"y="<<y;     //输出结果
12     }
13     else  {              //不满足条件执行
14        y=x*x; 
15        cout<<"y="<<y;    //输出结果
16     }
17     return 0;
18 }
原文地址:https://www.cnblogs.com/borter/p/9406224.html