以前一直认为在C语言中只有整形数据才能进行++,--的自增运算,今天发现其实我错了。例如看下面的一个程序:
#include <stdio.h>
//#include <string.h>
int main(void)
{
float x = 1;
float y;
y = ++x*++x;
printf("%f\n",y);
return 0;
}
在vc6.0中编译结果是这样的:
--------------------Configuration: test_one - Win32 Debug--------------------
Compiling...
test_One.cpp
test_One.obj - 0 error(s), 0 warning(s)
云行结果是这样的:
9.000000
Press any key to continue
而在vs2008中是这样的:
编译:
1>------ 已启动生成: 项目: testBKY, 配置: Debug Win32 ------
1>正在编译...
1>stdafx.cpp
1>正在编译...
1>testBKY.cpp
1>正在编译资源清单...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>正在链接...
1>正在嵌入清单...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>生成日志保存在“file://d:\Backup\我的文档\Visual Studio 2008\Projects\testBKY\testBKY\Debug\BuildLog.htm”
1>testBKY - 0 个错误,0 个警告
========== 生成: 成功 1 个,失败 0 个,最新 0 个,跳过 0 个 ==========
运行:
9.000000
Press any key to continue
可见不只是整形数据可以进行自增自减运算。