Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

5 Comments

Right-to-left associativity says this is interpreted as

a ? b : (c ? d : e);

not

(a ? b : c) ? d : e;

Those 2 expressions evaluate the same...

== has a higher precedence than ?:, and so it evaluates first regardless of parentheses.

but

a == b ? 0 : 1

and

a == ( b ? 0 : 1 )

are different (since the parentheses force b ? 0 : 1 to be evaluated before ==)

baboo_

lot of answers.

but i am actually interested in an example where

a ? b : c ? d : e;

if intrepreted as a ? b : (c ? d : e);

will give different answer than if interpreted as (a ? b : c) ? d : e;

just like 100/20/2 will give different ans if implemented as 100/(20/2) or (100/20) /2

waiting for a good easy to understand example.

Thanks.

x = 0; printf("%d",x==0?0:x==1?1:

x = 1; printf("%d",x==0?0:x==1?1:

x = 2; printf("%d",x==0?0:x==1?1:

x = 0; printf("%d",x==0?0:(x==1?1

x = 1; printf("%d",x==0?0:(x==1?1

x = 2; printf("%d",x==0?0:(x==1?1

x = 0; printf("%d",(x==0?0:x==1)?

x = 1; printf("%d",(x==0?0:x==1)?

x = 2; printf("%d",(x==0?0:x==1)?

produces:

012012212

showing that the first set is functionally the same as the second and therefore the third is the non-default option.

Paul

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Course of the Month13 days, 18 hours left to enroll

Join the community of 500,000 technology professionals and ask your questions.