What is the output of the following code? html
{ int x = 10; int y = 10; x = x++; y = ++y; printf("%d,%d\n",x,y); }
A.10,10 express
B.10,11 less
C.11,10 ide
D.11,11 測試
編譯器實際測試結果 spa
GCC : 11,11VC: 11,11 code
TCC:10,11 htm
STD C99 blog
第6.5.16部分第3條 get
An assignment operator stores a value in the object designated by the left operand. An
assignment expression has the value of the left operand after the assignment, but is not an
lvalue. Thetype of an assignment expression is the type of the left operand unless the
left operand has qualified type, in which case it is the unqualified version of the type of
the left operand. The side effect of updating the stored value of the left operand shall
occur between the previous and the next sequence point.
VC反彙編結果
x = x++;
004113DC mov eax,dword ptr [x]
004113DF mov dword ptr [x],eax
004113E2 mov ecx,dword ptr [x]
004113E5 add ecx,1
004113E8 mov dword ptr [x],ecx
y = ++y;
004113EB mov eax,dword ptr [y]
004113EE add eax,1
004113F1 mov dword ptr [y],eax
004113F4 mov ecx,dword ptr [y]
004113F7 mov dword ptr [y],ecx
到如今爲止合理的答案是D
不過,若是令
d = (x = x++);
TCC、VC的輸出,d爲10,很費解。
原題
http://www.cnblogs.com/justcxtoworld/archive/2013/04/06/3002719.html