0 votes 0 votes closed as a duplicate of: Undefined Behaviour in C Q)If a is 15, then what would be the value of: printf("%d , %d , %d , %d ", ++a , a++, --a , a--); A)16,16,16,16 B)15,13,15,15 C)16,15,14,14 D)16,16,14,14 Programming in C programming-in-c + – Lakshman Bhaiya asked Mar 1, 2018 • closed Mar 2, 2018 by Lakshman Bhaiya Lakshman Bhaiya 2.4k views comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments srestha commented Mar 1, 2018 reply Follow Share https://gateoverflow.in/62411/undefined-behaviour-in-c 1 votes 1 votes Akhilesh Singla commented Mar 1, 2018 reply Follow Share @Lakshman I think you are getting an output because most of today's C compilers does not fully adhere to the original C rules which actually hasn't defined for compilers what to do in such confused evaluations. 0 votes 0 votes Deeksha Sisodiya commented Mar 10, 2018 reply Follow Share Answer is option (a) 0 votes 0 votes Please log in or register to add a comment.
3 votes 3 votes This question is compiler dependent question, you may get different answers from different compilers but if you encounter this question you can use below approach but still it doesn't give exact answer. The print statement will be executed from right to left - so first a-- will happen as a-- is postfix so value of a-- = 15. then --a so already a value is 14 and now --a is prefix so value of --a = 13 then a++ its a postfix so value of a++ = 13 then ++a, already value of a became 14 now ++a is prefix so value of ++a = 15. But wait this all be printed in reverse direction because only execution is right to left but print will be from left to right, so answer will be 15, 13, 13, 15. pilluverma123 answered Mar 2, 2018 pilluverma123 comment Share Follow See 1 comment See all 1 1 comment reply I_am_winner commented Oct 13, 2018 reply Follow Share No answer is correct you mean here 0 votes 0 votes Please log in or register to add a comment.