conditional operator in C question
Posted
by Seephor
on Stack Overflow
See other posts from Stack Overflow
or by Seephor
Published on 2010-05-19T18:35:23Z
Indexed on
2010/05/19
18:40 UTC
Read the original article
Hit count: 305
I just have a quick question about the conditional operator. Still a budding programmer here. I am given x = 1, y = 2, and z = 3.
I want to know, why after this statement:
y += x-- ? z++ : --z;
That y is 5. The values after the statement are x = 0, y = 5, and z = 4. I know the way the conditional operator works is that it is formatted like this: variable = condition ? value if true : value if false.
For the condition, y += x-- , how does y become 5? I can only see 2 (2 += 0) and 3 (2 += 1)(then x-- becomes zero) as possibilities. Any help is much appreciated. :)
© Stack Overflow or respective owner