Re: [NEWBIE] question

From: Tony Robbins (
Date: 04/03/01

Quoting Del <caminturn@EARTHLINK.NET>:

> Peter Ajamian wrote:
> >
> > Close, but not quite.  The difference is that
> the former is an operator
> > which tests the first argument and returns
> either the second or the third
> > depending on the result.  The latter is a
> statement which tests the
> > expression and executes one of two code blocks
> depending on weather or
> > not it's true.  If that was too complex for
> you then I'll try to simplify
> > it with a couple of examples...
> >
> 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.

No.  It is a ternary operator, but not the same as what
you're trying to say.  It can be fudged a little, but
the essential difference is that the ? operator is used
to report a value, while an if statement can perform an

In other words:

when i = 1, and you use (i ? "true" : "false")
somewhere, the entire contents of the brackets is
replace by the static string "true".

When i = 0, the parenthesized is replaced with "false".

In English, if (i) then ("true") else ("false") is the
probably the second best way to say it.  You're
substituting a value though, so it's better to be said
if (i) then ([my value is] "true") else ([my value
is] "false").

Lastly, getting a book on C is definitely recommended.
If not because it's a quicker resource than the list,
then because it'll be less violent than the list
stating "get a ....... book."/RTFM.

-k. o O ( the next person to ask will get a "check the
archives", as well. :P )

   | FAQ: |
   | Archives: |

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