The Gateway to Computer Science Excellence
0 votes
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

in Programming by Loyal (8.1k points) | 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

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

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
198,593 comments
105,444 users