微软2013暑期实习笔试题目第5题分析
2013-04-08 00:00
393 查看
What is the output of the following code?
A.10,10
B.10,11
C.11,10
D.11,11
编译器实际测试结果
GCC : 11,11
VC: 11,11
TCC:10,11
STD C99
第6.5.16部分第3条
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
{ int x = 10; int y = 10; x = x++; y = ++y; printf("%d,%d\n",x,y); }
A.10,10
B.10,11
C.11,10
D.11,11
编译器实际测试结果
GCC : 11,11
VC: 11,11
TCC:10,11
STD C99
第6.5.16部分第3条
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
相关文章推荐
- 微软2013暑期实习笔试题目
- 微软2013暑期实习笔试题目
- 微软2013暑期实习笔试回忆
- 2011微软暑期实习笔试海选题目(欢迎讨论)
- 2013微软暑期实习笔试错题、疑题整理
- 2013微软暑期实习笔试&面试总结
- 笔试分析之腾讯2013暑期实习
- 微软2013暑期实习笔试回忆
- 微软2013暑期实习笔试回忆
- 2013微软暑期实习笔试题及答案
- 微软2013暑期实习笔试题(全)有兴趣可以看看哈
- 2014年江苏移动暑期实习笔试部分题目
- 微软2012暑期实习笔试题(附答案)
- 2012微软暑期实习笔试
- 腾讯2013暑期实习笔试&面试总结
- 微软2013年暑期实习招聘笔试回忆[转载]
- 2014年腾讯暑期实习笔试题(含分析)
- 微软2013年实习招聘笔试“22221111”题目详解
- 概率小数2013年阿里巴巴暑期实习招聘笔试题目(不完整,笔试时间:2013.5.5)
- 2012微软暑期实习笔试