a < b ? b : a

Discussion in 'C++' started by desktop, Apr 23, 2007.

  1. desktop

    desktop Guest

    I seem to have figured out that:

    a < b ? b : a

    returns a when a < b = false and b when a < b = true

    but what is the statment:

    Exp ? Exp : Exp

    called? Could not find anything describing it in my book Accelerated C++
     
    desktop, Apr 23, 2007
    #1
    1. Advertising

  2. desktop wrote:
    > I seem to have figured out that:
    >
    > a < b ? b : a
    >
    > returns a when a < b = false and b when a < b = true
    >
    > but what is the statment:
    >
    > Exp ? Exp : Exp
    >
    > called? Could not find anything describing it in my book Accelerated
    > C++


    The official name of that _operator_ is "conditional". As in
    "the conditional operator". It's the only *ternary* operator
    in C++ (one that has three operands). It's not overloadable.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Apr 23, 2007
    #2
    1. Advertising

  3. desktop

    Gavin Deane Guest

    On 23 Apr, 14:24, desktop <> wrote:
    > I seem to have figured out that:
    >
    > a < b ? b : a
    >
    > returns a when a < b = false and b when a < b = true
    >
    > but what is the statment:
    >
    > Exp ? Exp : Exp
    >
    > called? Could not find anything describing it in my book Accelerated C++


    The operator is called the Conditional Operator and an expression
    using it like your example is a Conditional Expression.

    Gavin Deane
     
    Gavin Deane, Apr 23, 2007
    #3
  4. desktop

    fcvcnet Guest

    desktop :
    > I seem to have figured out that:
    >
    > a < b ? b : a
    >
    > returns a when a < b = false and b when a < b = true
    >
    > but what is the statment:
    >
    > Exp ? Exp : Exp
    >
    > called? Could not find anything describing it in my book Accelerated C++

    cond ? expr1 : expr2;
    I think they are the same.

    --
    Thank you very much! :)
    Thank this newsgroup very much! :)
    Visual Studio 2005 Professional Edition
    Windows XP Professional
     
    fcvcnet, Apr 23, 2007
    #4
  5. "desktop" <> wrote in message
    news:f0ic0o$kcf$-c.dk...

    > but what is the statment:


    > Exp ? Exp : Exp


    > called? Could not find anything describing it in my book Accelerated C++


    It's on page 45, where it's described as the "conditional operator"

    Page 45, in turn, is mentioned in the index under the "?:" heading.
     
    Andrew Koenig, Apr 23, 2007
    #5
  6. desktop

    Ranok Guest

    It's called the conditional operator, though it's also commonly known
    as the ternary operator, since it's the only one in C++.

    Ranok
     
    Ranok, Apr 23, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page