Jump to content

Boostc - The Conditional Operator - ? :


Recommended Posts

I am having problems with the conditional operator in BoostC.

 

The conditional operator is normally defined and use as:

 

<expression1> ? <expression2> : <expression3>

 

When I write:

 

Some_Counter = 7;

Some_Counter++;

Some_Counter = (Some_Counter < 100) ? Some_Counter : 0;

 

The value of Some_Counter evaluates to 8 - fine.

 

But when I write:

 

Some_Counter = 7;

Some_Counter = (Some_Counter < 100) ? Some_Counter++ : 0;

 

The value of Some_Counter also evaluates to 7.

 

Is this correct? Your comments will be appreciated.

Link to post
Share on other sites

RSABear,

...

But when I write:

 

Some_Counter = 7;

Some_Counter = (Some_Counter < 100) ? Some_Counter++ : 0;

 

The value of Some_Counter also evaluates to 7.

 

Is this correct? Your comments will be appreciated.

Yes, to get what you want use:

 Some_Counter = (Some_Counter < 100) ? ++Some_Counter : 0;

 

Regards

Dave

Link to post
Share on other sites

RSABear,

Thanks Dave. What can I say? C is a "professional" programming language and is very specific on code syntax.
Its not a syntax thing, you need to realise that Some_Counter++; and ++Some_Counter; mean slightly different things. Which one you use depends what you want to do.

 

Regards

Dave

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...