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);

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

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

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

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

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

hey thanks ..this is really gud link u have provided ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.