What does this code mean ?
glHorizon_Project
www.web-discovery.net
OT: y=y<0?0:y
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
Anthracks
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."
syntax:
(expression1) ? (expression2) : (expression3)
"If expression1 is true,
return the value of expression2;
otherwise, return the value of expression3."
The best way I found to remeber it is just like an if statement:
a ? b : c
if a then b else c
a ? b : c
if a then b else c
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
http://nehe.gamedev.net/articles/article05.asp
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement