a < b ? b : a

D

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++
 
V

Victor Bazarov

desktop said:
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
 
G

Gavin Deane

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
 
F

fcvcnet

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.
 
R

Ranok

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top