-1

I've known that primary operator (x++) is different form unary operator (++x) when combine with another operator in a statement.

But I wonder whether those two operator is same when leave them alone on the statement. I mean about compiled code, time to run, ... between:

++x;

and

x++;

Which x is an integer variable.

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
Tu Tran
  • 1,957
  • 1
  • 27
  • 50

1 Answers1

4

It is the same in disassembly (not IL) on Windows 8 x64:

                ++x;
0000004a  inc         dword ptr [ebp-40h] 
                x++;
0000004d  inc         dword ptr [ebp-40h] 

As you can see, both statements are an inc instruction. I used this code to try out:

int x = 0;
for (int i = 0; i < 10; i++)
{
    ++x;
    x++;
}
Matthias Meid
  • 12,455
  • 7
  • 45
  • 79