When does a pre/post increment occur? Editing here to clarify. The headline asks the question but the example given was not ideal. This was a more general Q than about the example code.

Compilers have sequence points, places where you can be assured that the equations have been evaluated etc and no lingering effects will occur: the compilation is stable. When I couldn't test the original example I went looking for theory, and came across SE/SO posts where there was some discussion about issues like:

   int a = 1;
   int b = a++ - a++ + a++;


What would you expect the values of a and b to be after this? It turns out it hinges on whether the arithmetic operators are sequence points. Apparently this was not well settled in early versions of C, and in other languages (like Java) the results may differ yet again.

I now understand that an expression like (item++ &gt; max) contains no sequence points -- the &gt; operator does not trigger evaluation, but assignment operators and some arithmetic operators do. 

//================================

Original Q:

I've read several Qs here concerning x++ vs ++x but I don't see this specific case. I'm still something of a C novice here.

Do these two code fragments do the same thing?

  // assume itemNum == maxItem on entry

if (++itemNum &gt; maxItem) itemNum = 0;

if (itemNum++ &gt; maxItem) itemNum = 0;


I gather that when the increment takes effect depends on the occurrence a 'sequence point' but I don't know if the comparison creates such an inflection.
Both ++x and x++ increment the value of x. The difference is whether you evaluate the value of x in your expression (formula) before or after incrementing it.

int x1 = 0;
int y1 = 0;

int x2 = x1++; //Post-increment: Move current value of x1 (0) to x2, THEN increment x1
int y2 = ++y1; //Pre-increment: Increment y1. Then move the NEW value of y1 (1) to y2.


In the above, x2 will be 0, and y2 will be 1.

The same logic applies to your if expression. If you use pre-increment, your if statement makes its decision on the new value after incrementing it.

If you use post-increment, the if statement makes its decision based on the value before it's incremented.