ChetanaSforum

# how this code works?

## Recommended Posts

hi there, i have doubt with this code plz help me outmain(){int i=5;i=i++ * i++;printf("%d",i);}o/p: 27

##### Share on other sites

hi there, i have doubt with this code plz help me outmain(){int i=5;i=i++ * i++;printf("%d",i);}o/p: 27

Hai madhuripatil,The o/p of the code will be 30 (if i am not wrong)initially the value of i is 5. //i=i++ * i++;here the calculation will be done as i=5 * 65 bcoz i++ so it will take the value 5 for calcuation6 bcoz of the earlier i++so u will get 30 as the o/pArthy.

##### Share on other sites

hi there, i have doubt with this code plz help me outmain(){int i=5;i=i++ * i++;printf("%d",i);}o/p: 27

Hi,I think its 27 only cos first its 5*5 which is 25 and then the two increments which becomes 27As far as I feel increments does not effect if its in d same statement.Pl let me if its right or not?

##### Share on other sites

Hello the code is very simple....See first the value of i is replaced that is 5 * 5 = 25 ..and as it is two time increment so it will become 27.For more ex.. let the i = ++i * ++i;Now what will happened that first the pre-increment will take place i.e. I increment twice so it become 7 and the value return is 49..For more ex.. let the i = ++i * i++;if it like this the i replaced by 6 (as only one time pre increment) and result will be increment by 1 as one post increment. i.e 37..The code work like this :-First increment All pre increment then replace, calculate the value and then do the post increment..Hope this can make u understandbye abhishek

##### Share on other sites

Hello Friend,

The output of this program is undefined B'coz we can't modify the variable twice in between two segment points. Here i++ * i++ is modified twice. different compilers gives different output.

There are some more idiot codes like this which are having the same output i.e undefined output.

these are

1. int i=10;

int ar[20];

ar=i++ ;

2. int i=10;

i = ++i;

ANSI C has defined the standard that we can't modify the varible twice untill it is complete expression, a function call, or with logical (&&,|| etc.) operators.

##### Share on other sites

It's sequence point not segment point.

##### Share on other sites

hi there, i have doubt with this code plz help me outmain(){int i=5;i=i++ * i++;printf("%d",i);}o/p: 27

hi aarthy actually it suared first to 25 and as we have two post increment operators 25 will be incremented twice so as a result we will get 27.if we use preincremented operators the i value gets incre mented first twice to 7 and the final value will be printed as 49.otherwise if u use another variable (ie. k=i ++ * i++)then just 25 will be dispalyed for ur iinput

##### Share on other sites

Hello Friend,

The output of this program is undefined B'coz we can't modify the variable twice in between two segment points. Here i++ * i++ is modified twice. different compilers gives different output.

There are some more idiot codes like this which are having the same output i.e undefined output.

these are

1. int i=10;

int ar[20];

ar=i++ ;

2. int i=10;

i = ++i;

ANSI C has defined the standard that we can't modify the varible twice untill it is complete expression, a function call, or with logical (&&,|| etc.) operators.

could u plz explain wats idiotic in example 1 and 2.

and could u plz tell me the book or text which defines ANSI C standards.

## Create an account

Register a new account

Instructions Here

• ### Our picks

• LOGIC HEART Freshers Walkin for Software Developers
• 0 replies
• PRAGMAEDGE SOFTWARE Freshers Walkin for Trainee Software Engineers