【问题标题】:Different between x++ and ++x [duplicate]x++和++x之间的区别[重复]
【发布时间】:2013-06-14 11:52:28
【问题描述】:

我知道在语句中与另一个运算符组合时,主运算符 (x++) 与一元运算符 (++x) 不同。

但是我想知道这两个运算符在语句中单独放置时是否相同。我的意思是关于编译的代码、运行时间,... 之间:

++x;

x++;

其中x是一个整数变量。

【问题讨论】:

标签: c# compiler-construction post-increment pre-increment


【解决方案1】:

在 Windows 8 x64 上的反汇编(不是 IL)中是一样的:

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

如您所见,两条语句都是inc 指令。我用这段代码试了一下:

int x = 0;
for (int i = 0; i < 10; i++)
{
    ++x;
    x++;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-06
    • 2018-06-18
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多