1 votes 1 votes #include<stdio.h> int main() { int x, y = 7; x = ++y + ++y + y--; printf("%d\n", x); return 0; } What is the output of this code snippet ? A. 27 B. 26 C. 25 D. Compilation error Programming in C programming-in-c undefined-behaviour + – Abhisek Saha asked Aug 31, 2018 reopened Jul 11, 2022 by Arjun Abhisek Saha 587 views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply lakshaysaini2013 commented Sep 2, 2018 reply Follow Share https://www.geeksforgeeks.org/sequence-points-in-c-set-1/ See here might it will help you to understand. It is a sequence point problem 0 votes 0 votes Ravijha commented Jun 22, 2019 reply Follow Share A). 27 0 votes 0 votes Arjun commented Jul 11, 2022 reply Follow Share https://gateoverflow.in/62411/undefined-behaviour-in-c 0 votes 0 votes Please log in or register to add a comment.
–2 votes –2 votes Answer is A. 27 rtiwari95 answered Aug 31, 2018 rtiwari95 comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments Abhisek Saha commented Aug 31, 2018 reply Follow Share @talha hashim Then according to you, if x = ++y + y-- ; then it should be y => 8 ==> 7 and x = 8 + 8 = 16...right? But it gives 15. Why? 0 votes 0 votes Shaik Masthan commented Aug 31, 2018 reply Follow Share please avoid discussion on Undefined Behavior in C 1 votes 1 votes Arjun commented Aug 31, 2018 reply Follow Share There are 10 kinds of people in world - one who understand undefined behaviour and one who doesn't :) 4 votes 4 votes Please log in or register to add a comment.
–3 votes –3 votes (y=7) y-- -->y=7( y=y-1 will be perform at last) ++y -->y=y+1=7+1=8 (y=8, updated) ++y -->y=8+1=9 (y=9, updated) now x=y+y+y ----->(++y + ++y +y--) x=9+9+9=27 now y=y-1 will be implemented y=9-1=8 x=27,y=8 balaganesh answered Aug 31, 2018 balaganesh comment Share Follow See all 2 Comments See all 2 2 Comments reply Abhisek Saha commented Aug 31, 2018 reply Follow Share @balaganesh Then according to you, if x = ++y + y-- ; then it should be y => 8 ==> 7 and x = 8 + 8 = 16...right? But it gives 15. Why? 0 votes 0 votes balaganesh commented Sep 1, 2018 reply Follow Share After your question i have checked with various examples, I came to know that its depends upon the compiler. 0 votes 0 votes Please log in or register to add a comment.