4章9节三目运算符

来源:互联网 发布:绝牛网身份证查询软件 编辑:程序博客网 时间:2024/06/17 08:46

#include <iostream>
int main()
{
    using namespace std;
 int x,y,z;
 cout << "pls enter 2 numbers " << endl;
 cin >> x;
 cin >> y;

 z = (x>y) ? x: y;
  cout << "system will display a bigger number(z) :" << z << endl;
 // ?: 为条件运算符 是唯一一个需要三个操作数的运算符
      
 /*  用if表示等同于下
 if(x>y)
 z=x
 cout << "z is " << z << endl;
 else
 z=y
 cout << "z is " << z << endl;
 */
 cout << "z is  " << z <<endl;
 return 0;
}