void main()
int i=3;
if we r using ++i it will increment and it will asign to i so ans is 4
if we r using i++ it will increment but it assign to i so ans is 4
b'coz of i++ i value is 5.for clarifications execute the program


Not only is your example horribly broken, it's not even a valid example of the point you're trying to make.

>void main()
Implementation-defined behavior. main is required to return int.

Undefined behavior. The commas in an argument list do not constitute sequence points, and ++ modifies its operand.
Undefined behavior. You didn't include stdio.h, and functions that take variable arguments require a prototype in scope.

Implementation-defined behavior. You didn't include a header that declares getch, and getch isn't a standard function.


Haahaa, good one Narue, But hell yeah that example will only give out errors.

Btw, balu116, please use the code tags. Posting source code like that is rude.


When did this become the noob gets it wrong thread?

It seems a magnet for 1-post people to chip in with their "interpretation" only to be corrected for getting some aspect of "side effect" or "sequence point" wrong.


xD but it can't be helped but corrected. Since others who are new here might get it wrong (which happens a lot). A good code writing practice is always appreciated.

int i=10;
cout << ++i << i++ << ++i;

using Borland C++, the output will be: 131111
instead of the expected output: 111112

Why is it?

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.