女友给我一段代码,让我给出结果,代码如下:
Code
#include "stdio.h"int main(int argc, char* argv[]) { int i=3,j; j=sizeof(++i + ++i); printf("%d\n",i); return 0; }
我一看,不加思索的认为输出应该是:5
可是編譯出來一看答案竟然不是5,竟然是3 . 也就是说两个 ++i 根本就没执行。
我有点奇怪,就查了MSDN,才知道我的理解确实有误,sizeof 里的表达式是不计算的。
MSDN 上如下說:
Code
An expression. When used with an expression, sizeof can be specified with or without the parentheses. The expression is not evaluated.
呵呵,自己的错误大家有可能也有,写出来为大家提个醒!
转载于:https://www.cnblogs.com/xtrgm623/archive/2008/11/03/1325376.html
相关资源:JAVA上百实例源码以及开源项目