in Programming in C
2,342 views
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

in Programming in C
2.3k views

3 Comments

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

according to the standards of C

things like 

b = ++a * a++;

a=a++;    are undefined

0
0

1 Answer

3 votes
3 votes
Best answer

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

selected by
by

3 Comments

When i execute i got 36 why it is undefined value ?
0
0

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
4
edited by
Have u executed the code I think it correct I'm getting different results thank u
0
0

Related questions