0 votes 0 votes What is the output of given program? #include<stdio.h> int main() { int x; x = 4 > 8 ? 5!= 1<5 == 0 ? 1:2:3; printf("%d",x); return 0; } option a. 1 b.2 c.3 d.compilation error Sahil Raza asked Aug 28, 2018 Sahil Raza 1.2k views answer comment Share Follow See all 9 Comments See all 9 9 Comments reply Show 6 previous comments Ravi Dubey commented Aug 28, 2018 reply Follow Share @Shaik masthan will you please explain the order of evaluation of your code I am not getting for multiple ternary operation? 0 votes 0 votes Shaik Masthan commented Aug 29, 2018 reply Follow Share @Ravi Dubey h=a++?b++?c++?d++:e++:f++:g++; note that ternary operator is right associative. step 1:- h = a++ ? b++ ? ( (c++) ? (d++) : (e++) ) : f++ : g++ ; step 2:- h = a++ ? ( (b++) ? ( (c++) ? (d++) : (e++) ) : (f++) ): g++ ; step 3:- h = ( (a++) ? ( (b++) ? ( (c++) ? (d++) : (e++) ) : (f++) ): (g++) ) ; finally it look like as, $h = (\, \, \, \underbrace{ (a++) }\, \, \, ? \, \, \, \underbrace{ (\, \, \, \overbrace{ (b++)} \, \, \, ?\, \, \, \overbrace{ ( \, \, \, \underbrace{(c++)} \, \, \, ? \, \, \, \underbrace{(d++)} :\, \, \, \underbrace{(e++)} \, \, \, )} : \overbrace{(f++)} \, \, \, )} : \underbrace{ (g++) }\, \, \,) ;$ after parenthesize, i hope it is simple, first evaluate expr1 (a++) ==> return true ( return 10 which is non-zero but note that after sequence point a=11 ) evaluate expr2 of first ternary operator ==> ( (b++) ? (c++?d++:e++) : (f++) ) evaluate b++ ===> return false ====> evaluates f++ and return that value to h 1 votes 1 votes Ravi Dubey commented Aug 29, 2018 reply Follow Share @shaik masthan really thanks I understood. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Answer: 3 Refer this: http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm ushamya answered Aug 29, 2018 ushamya comment Share Follow See all 0 reply Please log in or register to add a comment.