关于面试宝典5.4节类型转换的一道题目
输出:程序代码:
#include<iostream> using namespace std; int main() { int a = 0xfffffff7; char i = (char)a; char *b = (char*)&a; printf("1: %08x\n2: %08x\n", i, *b); unsigned int a2 = 0xfffffff7; unsigned char i2 = (unsigned char)a2; char *b2 = (char*)&a2; printf("2: %08x\n4: %08x\n", i2, *b2); return 0; }
1: fffffff7
2: fffffff7
2: 000000f7
4: fffffff7
请按任意键继续. . .
请问结果4的补0或是补1的原理,难道就看截取的f7的最高位是0还是1吗?
而且,结果1为什么是fffffff7呢?