0 votes 0 votes #include<stdio.h> int main() { int a = 5; int b = ++a * a++; printf("%d ",b); return 0; } (a) 25 (b) 30 (c) 36 (d) Undefined Behavior Programming in C programming-in-c output interview + – Desert_Warrior asked May 16, 2016 Desert_Warrior 2.3k views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply shivanisrivarshini commented May 16, 2016 reply Follow Share I got 36 as answer why cant it results output why undefined value 0 votes 0 votes Amit Prakash Tiwari commented Aug 4, 2016 reply Follow Share I don't know why I got the answer 42 running this code on https://www.codechef.com/ide and http://code.geeksforgeeks.org. Theoratically ,I know that the answer would be compiler dependent. 0 votes 0 votes chandra sai commented Sep 26, 2017 reply Follow Share according to the standards of C things like b = ++a * a++; a=a++; are undefined 0 votes 0 votes Please log in or register to add a comment.
Best answer 3 votes 3 votes Ans should be D) Undefined Behavior as here variable n is modified multiple time and not any intermediate sequenced .so it gives undefined behavior . you can refer here also : http://gatecse.in/wiki/Undefined_Value minal answered May 16, 2016 selected May 16, 2016 by srestha minal comment Share Follow See all 3 Comments See all 3 3 Comments reply shivanisrivarshini commented May 16, 2016 reply Follow Share When i execute i got 36 why it is undefined value ? 0 votes 0 votes minal commented May 16, 2016 reply Follow Share yes , different compile give different values . "Undefined value means compiler can give any value. i.e.; different compilers or even different versions of the same compiler can give different answers. As per C standard, no programmer should write this code. This is different from compiler defined, in which case the output is clearly defined by the compiler and programmer can write those code as long as he is aware of the compiler 4 votes 4 votes shivanisrivarshini commented May 16, 2016 i edited by shivanisrivarshini May 16, 2016 reply Follow Share Have u executed the code I think it correct I'm getting different results thank u 0 votes 0 votes Please log in or register to add a comment.