secondNu-6ren">
gpt4 book ai didi

c++ - C++一行代码中的 "?"和 ":"字符是做什么的

转载 作者:太空宇宙 更新时间:2023-11-04 15:55:50 25 4
gpt4 key购买 nike

我只是想知道 "?"":" 字符的作用。我正在处理一个问题并遇到了 ?。该解决方案显示一个问号,我不知道它的作用。 : 运算符还有什么作用?

return firstNum > secondNum ? vector<int>{secondNum, firstNum}:vector<int>{firstNum, secondNum};

最佳答案

这是ternary conditional operator

E1 ? E2 : E3        

The first operand of the conditional operator is evaluated and contextually converted to bool. After both the value evaluation and all side effects of the first operand are completed, if the result was true, the second operand is evaluated. If the result was false, the third operand is evaluated.

关于c++ - C++一行代码中的 "?"和 ":"字符是做什么的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58278221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com