By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

what does this statement mean?

P: n/a
Hi,
I came across this statement and it has a confusing element. I know the
whole '?:" construct and the assignment within the compare, but what's up
with the comma?

All the variables here are declared as doubles.

rtb = f < 0.0 ? (dx=x2-x1,x1) : (dx=x1-x2,x2)

Specifically, (dx=x2-x1,x1)? How do I read this?

Thanks!

Jay

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Comma can be used to separate expressions, the result of the overall
expression is the result of the last one. So...

If f is less than zero, then dx gets set to x2 minus x1, and then the
value of x1 is assigned to rtb.
Jul 23 '05 #2

P: n/a
Jay Wolfe wrote:
Hi,
I came across this statement and it has a confusing element. I know the
whole '?:" construct and the assignment within the compare, but what's up
with the comma?

All the variables here are declared as doubles.

rtb = f < 0.0 ? (dx=x2-x1,x1) : (dx=x1-x2,x2)

Specifically, (dx=x2-x1,x1)? How do I read this?


The whole line is equivalent to:

if (f < 0.0)
{
dx = x2 - x1;
rtb = x1;
}
else
{
dx = x1 - x2;
rtb = x2;
}

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.