0

hi ..
if anyone cn plz tell me wht will be the output of following code n how dis output is generated ...

float i=10;
printf("i++/i %f\n",i++/i);
printf("%f \n",i);
i=10;
printf("i/++i %f \n",i/++i);
printf("%f \n",i);
i=10;
printf("i++/++i %f \n",i++/++i);
printf("%f \n",i);
i=10;
printf("++i/i %f \n",++i/i);
printf("%f \n",i);

2
Contributors
6
Replies
7
Views
11 Years
Discussion Span
Last Post by joshilay
0

The output is undefined, there's no correct answer to your question.

i guess i have to repeat my question for clarification ... can u tell me how the following output is generated ...


int i=10;
printf(" %d ",i++/i); //output=0
i=10;
printf("%d",i/++i); //output=1
i=10;
printf("%d ",i++/++i); //output=0
i=10;
printf("%d",++i/i); //output=1

0

>i guess i have to repeat my question for clarification
To which you'll get the same answer. The output is undefined. Anything could happen, therefore there is no way to explain the output you're getting, and anyone who attempts to is guaranteed to be wrong. Perhaps rather than repeating your question, having completely failed to understand my answer, you should ask why the code is undefined. You'll learn a great deal more that way.

0

i guess i havnet understand the concept ..so can u please make me understand ...and tell me why the code is undefined ...

0

>i++/++i
The C (and C++) language definition says that if you modify an object more than once between sequence points, the behavior is undefined (so there's no such thing as "a little undefined behavior is okay" just as one can't be a little pregnant or a little dead). Undefined behavior anywhere in the program means that the entire program is undefined. Undefined behavior is about the worst thing you could have in a program because it produces completely unpredictable behavior, including, but not limited to: working properly, working improperly, erasing your hard drive, frying your monitor, sending nasty emails to your boss, and causing demons to fly out your nose.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.