July 13, 2024, 08:18:30 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Weird C synthax Topic :)

Started by pistol350, July 09, 2007, 04:27:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pistol350

Hi all!
Is there anyone out there who understands the meaning of this synthax ?
??? ??? ???

xincr = x2 > x1 ? 1 : -1;

thanks!
Regards,

Peter B.

Ionic Wind Support Team

That's C's infamous ternary operator.   It is just a shorthand IF statement.

if(x2 > x1)
    xincr = 1
else
    xincr = -1;


The ternary operator can lead to the most unreadable code that C programmers can write.  Especially when they nest it.

Paul.
Ionic Wind Support Team

pistol350

Thanks Paul!
QuoteThe ternary operator can lead to the most unreadable code that C programmers can write.  Especially when they nest it.

Unlucky me! i often stumble on this king of code  ;D
Regards,

Peter B.