0 votes 0 votes why the o/p of this programm is 12 ? #include<stdio.h> int main() { int x = 10; int y = (x++, ++x); printf("%d", y); getchar(); return 0; } DS programming-in-c + – Don't you worry asked Jul 15, 2016 Don't you worry 536 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply papesh commented Jul 16, 2016 reply Follow Share Try to run this code from different compiler... There will be difference in out put... 0 votes 0 votes Don't you worry commented Jul 16, 2016 reply Follow Share @gabbar can you explain the reason ? 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes If y =(value 1, value 2) y will be assigned with value 2. Here initially x=10 In (x++, ++x), the expression x++ makes x=11, then ++x again increments x to 12. this final value is assigned to y That's why output is 12 sh!va answered Jul 16, 2016 sh!va comment Share Follow See all 3 Comments See all 3 3 Comments reply Don't you worry commented Jul 16, 2016 reply Follow Share @shiva as you said y will get the value 2 then why we are even considering the x++ increment in this assignment y = (x++, ++x); if this is the case y =(value 1, value 2) y will be assigned with value 2. as you said then this int y = (x++, ++x); should be simpily one time increment just to consider ++x. 0 votes 0 votes sh!va commented Jul 16, 2016 i edited by sh!va Jul 16, 2016 reply Follow Share int y = (x++, ++x); compiler understands the line like this int y // y is an integer; allocate memory for it = // a value will be assigned ( // one or more operations are bundled together x++ // increment x by one x=11 , / / more operations are waiting, proceed!! ++x //increment x by one x=12 ) //operations are over, assign value of last operation to y ; ie y=12 ; // line is completed. Hope I could help you to understand 0 votes 0 votes Don't you worry commented Jul 16, 2016 reply Follow Share @shiva yes it has explained lots of thing. 0 votes 0 votes Please log in or register to add a comment.