View Single Post
Old 06-15-2002, 08:56 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
thanks redhead that is a good point ..

so you are saying that it is just the equivelent to:

if(condition 1)
{
expression1;
} else {
expression1;
}

and that is not saving you if/else statements, .. it's just saving you 1 if else statement.

... i guess it's useful as shorthand .. also. you can use it even in your cout statement or defining a variable.. i do like that.

i.e. variable = (condition1) ? expression1 : expression2;

or

cout << "the ternary result is " << ((condition1)?expression1:expression2);

i was trying to get it to work in the cout statement for a while the other night, but then i realized you must have the surrounding " ( ) " to make it work.

Last edited by sde; 06-15-2002 at 09:03 AM.
sde is offline   Reply With Quote