The Gateway to Computer Science Excellence
0 votes
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 by Loyal (8.1k points) | 261 views
I got 36 as answer why cant it results output why undefined value
I don't know why I got the answer 42 running this code on and   Theoratically ,I know that the answer would be compiler dependent.

according to the standards of C

things like 

b = ++a * a++;

a=a++;    are undefined

1 Answer

+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 :

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

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

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

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,392 answers
105,444 users