0 votes 0 votes Output will be- int main() { int a =0,b=1,c=3: *((a)?&b:&a)=a ? b : c; printf("%d %d%d ", a,b,c); } O/P AT LAST ? Deepanshu asked Jan 3, 2019 Deepanshu 522 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Shaik Masthan commented Jan 3, 2019 reply Follow Share From where you get this beautiful question ? Basic point, &* are inverse to each other. *((a)?&b:&a) = a ? b : c; if you clearly observe, *((a)?&b:&a) is simply as, if a=0, then it is *( address of a ) ===> assigning value to a if a=1, then it is *( address of b ) ===> assigning value to b But why it is written, like * ( & ) ? due to they apply ternary operator ==> it result r-value but not l-value, So they indirectly use like this. First evaluate right side of "=" operator ( as per associativity and precedence rule ) ==> which results value of c, i.e., 3 Assign it to a ∴ a = 3 Now i have a doubt, that " Is it lead to undefined behavior ? " Ans : NO, think why it is not undefined behavior. 1 votes 1 votes Deepanshu commented Jan 3, 2019 reply Follow Share Shaik Masthan question is from let us c : ) i am not getting u ... see how i approach as ternary is right to left operator so first a=0 which is false so we evaluate c which is 3 .. now goes inton this *((a)?&b:&a) a is false again inside so i am evaluating *(&a ) =a ?b:c now at this step i dont know what to do after this 0 votes 0 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes Precedence of () > ?: > = So, ${}^*((a)?\&b:\&a)= (a ? b : c);$ ${}^*((a)?\&b:\&a) = {}^*(\&a)$, because a = 0 $a ? b : c = c$, as a = 0 ${}^*(\&a) = c, \,a=3$ printf("%d %d%d ", a,b,c); prints $3,1,3$ Shobhit Joshi answered Jan 3, 2019 • selected Jan 3, 2019 by Deepanshu Shobhit Joshi comment Share Follow See all 7 Comments See all 7 7 Comments reply Show 4 previous comments Shobhit Joshi commented Jan 4, 2019 reply Follow Share as far as I know there is no order of evaluation, there is just precedence, the order of evaluation completely depends on the compiler, so the above code can evaluate right or left depends on the compiler. You can correct me if I'm wrong 0 votes 0 votes Shobhit Joshi commented Jan 4, 2019 reply Follow Share how can order of evaluation can be avoided with precedence and associativity, they are different terms. 0 votes 0 votes Shaik Masthan commented Jan 4, 2019 reply Follow Share sorry it's my mistake ! 0 votes 0 votes Please log in or register to add a comment.