首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C语言 之 细节1

2012-08-22 
C语言 之 细节一这三行输出应该是什么?#include stdio.hint main(){int ii 10printf(%d\n, i)pri

C语言 之 细节一
这三行输出应该是什么?

#include <stdio.h>
  int main()
  {
  int i;
  i = 10;
  printf("%d\n", i);
  printf("%d\n", sizeof(i++));
  printf("%d\n", i);
  return 0;
  }


求解释啊!

[解决办法]

C/C++ code
    printf("%d\n", sizeof(i++));00901410  mov         esi,esp  00901412  push        4  //直接是4,sizeof不是函数00901414  push        905858h  00901419  call        dword ptr ds:[9092BCh]  0090141F  add         esp,8  00901422  cmp         esi,esp  00901424  call        __RTC_CheckEsp (0901136h)
[解决办法]
C++标准:

5.3.3 sizeof
The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is an unevaluated operand (Clause 5), or a parenthesized type-id.”

也就是说,如果sizeof的操作数是一个表达式的话,这个表达式时不会被计算的。
另外一个操作符typeid也是如此。

热点排行