1. ## Please explain me this concept!!

Here is a code

int i=7;
printf("%d\n", i++*i++);

this gives the output 56.
I have learned that increment or decrement is performed immediately after giving up the previous value and before any other part of the expression is evaluated.And i know that post increment means assign the value first and then increment.
But how exactly is the output calculated??? What is sequence point and what does it has to do with this code???

2. Implementation defined

EDIT: Ups, not the information I wanted it to be...

EDIT^2 : Maybe this one?

3. Thank u so much for the link , it was very helpful.

4. Short answer: Never do this in real-life code.

It's nothing more than an intellectual exercise in understanding undefined behaviour.

5. Given the frequency with which we see this question being asked, I'm not so sure it really *is* about understanding undefined behavior. I think they're actually teaching this as valid code, expecting the answer to be whatever Turbo Crap gives them.

6. Originally Posted by rags_to_riches
Given the frequency with which we see this question being asked, I'm not so sure it really *is* about understanding undefined behavior. I think they're actually teaching this as valid code, expecting the answer to be whatever Turbo Crap gives them.
I disagree. I've lost count of the number of people I've seen asking a variation of this question, and have seen no correlation between those people and their choice of compiler.

Sometimes it a case learning to use expressions like "z = a++ + ++b;" (i.e. multiple variables incremented in one expression) safely, so they assume they can get away with incrementing a variable twice, such as "z = a++ + ++a;". And they find they don't get the result they expect.

I have also seen plenty of cases, like the OP in this case, giving some relevant words ("sequence point", "undefined", etc) which implies that someone has already tried to explain (or teach) what is going on.

I think this comes up a lot because people are people. Some make incorrect leaps of judgement (eg if I can increment two variables in an expression, I can increment one variable twice. Oh, bugger, why isn't it doing what I expect?). Some don't quite grasp what their teacher or textbook is telling them (teacher says this is "undefined" but it produces the value 56 rather than 58 - huh??) - which can be due to poor teaching, to inattention by the student, or simply due to a human misunderstanding.

The thing is, once you know this type of thing, it's pretty easy to understand (unless you try to write obscure one-liners for obfuscated C contests). But, when you first learn, there are a lot of subtleties. So even the best students can misunderstand at first.

7. If your "tutor" claims to know "the answer", then feel free to show them this experiment with several compilers and ask them to explain all the results.

And by explain, I mean to the extent that you can then compile the code with the "code-masher 4.5 C compiler" and be able to predict the output BEFORE running the code.

You see, with well-formed code which has no undefined behaviour, you can describe what will happen without having to run the code.

With the code you posted - you're screwed before you begin.