1 1 vote closed with the note: It has sequence point problem. #include<stdio.h> void main(){ int i=11; printf("%d \n", i++|++i); printf("%d",i); } Output is: 15 13 I understand how 13 came but I don't get how 15 came. And why there is no sequence point problem in this? Programming in C programming-in-c + – Akhilesh Singla 1.3k views comment Share Follow Print 0 reply Please log in or register to add a comment.
1 1 vote bro take this line printf("%d \n", i++|++i); this is nothing but 11 = 1011 12 = 1100 11 || 12 = (1011 | 1100) = BitwiseOR(1011,1100) = (1111)2 = (15)10 Salazar answered Mar 18, 2018 Salazar comment Share Follow See all 7 Comments 7 7 Comments reply Akhilesh Singla commented Mar 18, 2018 reply Follow flag What is the order of evaluation: ++i then i++ "or" i++ then ++i? According to precedence table unary operators are evaluated right to left. Does the first one evaluated in any of them save the changes in the original 'i' variable or not? 0 0 replyShare Salazar commented Mar 18, 2018 reply Follow flag Reference 0 0 replyShare Akhilesh Singla commented Mar 18, 2018 reply Follow flag Thank you. Could you please check out this code: jdoodle.com/a/qvv I do not understand how its output is 13. 0 0 replyShare srestha commented Mar 18, 2018 reply Follow flag why do u think, there will be no sequence point problem? 1 1 replyShare Akhilesh Singla commented Mar 18, 2018 reply Follow flag Because we are only evaluating one expression in printf. For example, printf("%d %d",++i|i++,++i); this would be a sequence point problem because it involves two expressions to be evaluated on a single variable without using valid sequence point(s). Am I wrong or right?! 0 0 replyShare Salazar commented Mar 18, 2018 reply Follow flag i think it's fair to say the output is compiler implementation dependent, do you agree @srestha ? 0 0 replyShare Devshree Dubey commented Mar 18, 2018 reply Follow flag @Akhilesh Singla,please go to my comment section in the original question and check please. I hope it helps u. 0 0 replyShare Please log in or register to add a comment.