void TestMain()
{
int i;
char c;
short s;
float f;
c = -1;
f = (float)c;
LOGE("1. c:0x%x\n", c);
LOGE("1. f:%lf\n", f);
c = 0;
f = c;
LOGE("2. c:0x%x\n", c);
LOGE("2. f:%lf\n", f);
c = -1;
f = c;
for (int i = 0; i < 1000; i++){
f = f + c;
}
LOGI("3. f + c:%lf\n", f);
i = -1;
f = i;
for (int idx = 0; idx < 1000; idx ++){
f = f + i;
}
LOGI("3. f + i:%lf\n", f);
c = 0;
i = 1;
f = (!c)*(i);
for (int idx = 0; idx < 5; idx++){
f = f + f;
}
LOGE("4. f:%lf\n", f);
s = -1;
f = s;
LOGE("5. f:%lf\n", f);
}
===============android=====================
04-10 22:40:30.108 27946-27946/com.example.myapplication E/DYZ: 1. c:0xff
04-10 22:40:30.108 27946-27946/com.example.myapplication E/DYZ: 1. f:255.000000
04-10 22:40:30.108 27946-27946/com.example.myapplication E/DYZ: 2. c:0x0
04-10 22:40:30.109 27946-27946/com.example.myapplication E/DYZ: 2. f:0.000000
04-10 22:40:30.109 27946-27946/com.example.myapplication I/DYZ: 3. f + c:255255.000000
04-10 22:40:30.109 27946-27946/com.example.myapplication I/DYZ: 3. f + i:-1001.000000
04-10 22:40:30.109 27946-27946/com.example.myapplication E/DYZ: 4. f:32.000000
04-10 22:40:30.109 27946-27946/com.example.myapplication E/DYZ: 5. f:-1.000000
=================windows====================
1. c:0xffffffff
1. f:-1.000000
2. c:0x0
2. f:0.000000
3. f + c:-1001.000000
3. f + i:-1001.000000
4. f:32.000000
5. f:-1.000000

本文通过一系列C语言实验,深入探讨了不同数据类型之间的转换规则,包括字符型、整型、浮点型等基本类型间的相互转换,并分析了类型转换对数值计算的影响。通过对比Android和Windows平台的实验结果,揭示了平台差异对类型转换表现的影响。

4955

被折叠的 条评论
为什么被折叠?



