[Courses] [C] Chapter 4d

Kathryn Hogg kjh at flyballdogs.com
Fri Oct 11 16:44:13 EST 2002


> In this case, ++x and x++ are the same.
> They differ when you use them for things like arrays

To be more precise, the difference between ++x and x++ is only apparant if
the calling expression cares about the value of the expression:

   int i;
   int x = 1;

    i = x++;
    printf("%d %d\n", i, x);
    i = ++x;
    printf("%d %d\n", i, x);


should generate

1 2
3 3

In an expression like
      x++;

we're not doing anything with the result of x++ so whether it is pre or
post  increment is largely irrelevant.



-- 
Kathryn





More information about the Courses mailing list