Jump to content
  • Advertisement

Archived

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

penetrator

OT: y=y<0?0:y

This topic is 6040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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
Check out NeHe''s site under OpenGL articles, Handy Compilation of C/C++ Methods. It''s where I first heard of it.

http://nehe.gamedev.net/articles/article05.asp

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!