2 votes 2 votes int main(){ int i=5,j; j=++i + ++i + ++i; printf("%d %d",i,j); return 0; } https://gateoverflow.in/?qa=blob&qa_blobid=15560219953750733487 please explain how j = 22 comes in output?? Programming in C programming-in-c output interview + – indrajeet asked Jul 19, 2016 indrajeet 4.1k views answer comment Share Follow See all 8 Comments See all 8 8 Comments reply papesh commented Jul 20, 2016 reply Follow Share Undefined behavior... This type of question won't be asked in gate... 2 votes 2 votes dd commented Jul 20, 2016 i edited by dd Jul 20, 2016 reply Follow Share precedence of (++) pre increment is greater than addition (+) Using GCC: Output : i= 4 k= 6 l= 10 m= 7 j= 27 Same procedure is followed in case of all i's Output : i= 7 j= 23 Now in case of your question : j = (7+7) + 8 = 22 Using C99 strict : Two different versions giving different answers. http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points 2 votes 2 votes ManojK commented Jul 20, 2016 reply Follow Share Can you tell me what will be result if int i=6; k=i++ * i++ ; what value is stored in k ? 1 votes 1 votes dd commented Jul 20, 2016 reply Follow Share I tried the following ..correct me if wrong 1 votes 1 votes ManojK commented Jul 20, 2016 reply Follow Share Ok then first read this link http://www.geeksforgeeks.org/sequence-points-in-c-set-1/ Then run this program #include<stdio.h> int main() { int i=6; int k=i++ * i++ ; printf("%d",k); } two link are here just run ones. 1.http://codepad.org/ 2.https://ideone.com/ 2 votes 2 votes Kapil commented Jul 20, 2016 reply Follow Share @Manojk, sir, these type of questions are undefined behaviour... answer can be 36 or 42... they dont hv a particular answer.. 2 votes 2 votes ManojK commented Jul 20, 2016 reply Follow Share yes . 0 votes 0 votes dd commented Jul 20, 2016 i edited by dd Jul 20, 2016 reply Follow Share yes ambiguity....in c99 strict it is giving 36 and in later version or in gcc giving 42 // thanks sir anyway learned about sequence point error 3 votes 3 votes Please log in or register to add a comment.
–1 votes –1 votes the answer this program is 8,22 explanation: As per the program i=5 j=++i + ++i + ++i (i.e., pre-increament=6+8+8) http://www.tutorialspoint.com/compile_c_online.php , https://www.codechef.com/ide j=22 and a=8 jaiganeshcse94 answered Jul 21, 2016 • edited Jul 22, 2016 by jaiganeshcse94 jaiganeshcse94 comment Share Follow See all 0 reply Please log in or register to add a comment.