261 views
#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

| 261 views
0
I got 36 as answer why cant it results output why undefined value
0
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

according to the standards of C

things like

b = ++a * a++;

a=a++;    are undefined

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

by Boss (17.1k points)
selected by
0
When i execute i got 36 why it is undefined value ?
+4

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

0
Have u executed the code I think it correct I'm getting different results thank u