May 01, 2024, 10:21:42 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


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.