How do I use the conditional operator?

后端 未结 9 1050
忘了有多久
忘了有多久 2020-11-22 16:27

I\'ve always wondered how to write the \"A ? B : C\" syntax in a C++ compatible language.

I think it works something like: (Pseudo

9条回答
  •  深忆病人
    2020-11-22 17:03

    In c++ there's no actual if part of this. It's called the ternary operator. It's used like this: ? : ; For your example above it would look like this:

    C = A > B ? A : B;
    

    This article on wikipedia also discusses it: http://en.wikipedia.org/wiki/Ternary_operation

提交回复
热议问题