复合表达式

如 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 }

 

相关文章:

  • 2022-01-14
  • 2021-08-23
  • 2021-09-18
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2021-05-21
  • 2021-06-21
猜你喜欢
  • 2021-09-11
  • 2021-06-20
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案