Skip to main content
gamedev.net
🔒 Locked

Help with C++ expression

Started by penetrator 4 replies 1.4k views
Original Post
penetrator
penetrator
Hi, could you please explain what the following expression does ? value = (float) X + ( ( nTri == 1 || nTri == 2 || nTri == 5 ) ? Resolution : Scale );
DigitalDelusion
DigitalDelusion
it does this:
value = (float)X;if( nTri == 1 || nTri == 2 || nTri == 5 )//nTri == 1, 2, or 5  value += Resolution;else  value += Scale;


why it does it otoh I have no idea :p
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Evil Steve
Evil Steve
value = (float) X + ( ( nTri == 1 || nTri == 2 || nTri == 5 ) ? Resolution : Scale );
is the same as:
if(nTri==1 || nTri==2 || nTri==5)   value = (float) X + Resolution;else   value = (float) X + Scale;

Just in a shorter form.

EDIT: Bah, beaten [smile]
bkt
bkt
Inline if-statements are god.
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]
Xipher
Xipher
actually, the ? : is a trinary operator, not so much an inline if statment.
Miserable
Miserable
The key difference between the ternary operator and an if-statement is actually what the OP implies in the topic name: It's an expression, not a statement.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.