Re: [NEWBIE] question

From: Mike Breuer (mbreuer@new.rr.com)
Date: 04/03/01


> Yes it is an operator, but why is it different than an if statment?
> Does it not do the same thing? i.e. Both check the value, and if the value
> is true, do the first, if not do the second.

The main difference between the ternary operator and an if statement is that
a ternary operator returns a value but an if statement does not.  (note that
the if _expression_ returns a value, but not the statement).   In nearly
every case a ternary operator can be replaced with an if..else clause.  I
usually tell C students that you don't have to use it if you don't like it,
but it is important that you understand it so that you can read other
people's code.

Mike

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/05/01 PST