Archived

This topic is now archived and is closed to further replies.

penetrator

OT: y=y<0?0:y

Recommended Posts

Guest Anonymous Poster
y = y < 0 ? 0 : y

is the same as:

if (y < 0) { y = 0 } else { y = y }

it''s just a shortcut

Share this post


Link to post
Share on other sites
That must seriously set some kind of record for "wackiest syntax", it is definitely one of the most confusing (yet simple) things I''ve run across in C .

Anthracks

Share this post


Link to post
Share on other sites
it''s called a Ternary operator

syntax:
(expression1) ? (expression2) : (expression3)
"If expression1 is true,
return the value of expression2;
otherwise, return the value of expression3."

Share this post


Link to post
Share on other sites