1

If int var=20 then how

printf("%d %d %d", var--, ++var, --var); 

execution happens in C programming language.

stacker
  • 68,052
  • 28
  • 140
  • 210
Mahesh
  • 19
  • 1
  • There are quite a few very similar questions about undefined behaviour on SO already, e.g. http://stackoverflow.com/questions/2902638/post-and-pre-increment-in-c and many more... – Paul R Jun 24 '10 at 11:29

1 Answers1

8

It is undefined behaviour because var is modified several times without a sequence point in between. A sequence point would be, for example, a ;. The commas in parameter lists, do, however, not introduce sequence points, also the order in which the operands are evaluated is undefined (you could say, the code is doubly undefined ...).

Alexander Gessler
  • 45,603
  • 7
  • 82
  • 122
  • 4
    The order in which the operands are evaluated is not undefined, it is unspecified (there is an evaluation order, the implementation just doesn't have to document it nor to be consistent -- even between two executions of the same code line). – AProgrammer Jun 24 '10 at 11:32
  • You might want to consider the sequence of function parameter is being processed. – YeenFei Jun 24 '10 at 12:55