C++三目运算符-C++的三目运算符-C++三目运算符怎么用-什么是三目运算符-嗨客网

PHOTO EMBED

Thu Dec 08 2022 02:54:20 GMT+0000 (Coordinated Universal Time)

Saved by @leawoliu

#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
	cout << "嗨客网(www.haicoder.net)\n" << endl;
	//三目运算符嵌套使用
	int a = 100, b = 200, c = 300;
	int retValue = a > b ? (a > c ? a : c)  : (b > c ? b : c);
	cout << "MaxValue = " << retValue << endl;
}
content_copyCOPY

三目运算符嵌套 C++ 的三目运算符,可以嵌套使用 #include <iostream> using namespace std; int main(int argc, char **argv) { cout << "嗨客网(www.haicoder.net)\n" << endl; //三目运算符嵌套使用 int a = 100, b = 200, c = 300; int retValue = a > b ? (a > c ? a : c) : (b > c ? b : c); cout << "MaxValue = " << retValue << endl; }

https://haicoder.net/cpp/cpp-ternary-operator.html