返回信息流void show(char* p) // 这里p是char还是unsigned char,有很大区别,为什么?
{
int i=0;
for (i;i<4;i++)
{
printf("%2x",*(p+i));
putchar(10);
}
printf("\n");
}
int main()
{
int a = -16;
show(&a);
}
p 是char时,输出:
fffffff0
ffffffff
ffffffff
ffffffff
p是unsigned char时,输出:
f0
ff
ff
ff
请问学霸这是为什么
这是一条镜像帖。来源:北邮人论坛 / cpp / #77260同步于 2014/3/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
unsigned char与char指针的问题
BaiWfg2
2014/3/2镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
这……你用的什么编译器,我这里连编译都通不过:'show' : cannot convert parameter 1 from 'int *' to 'unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
我这边VC6也不能编译通过,最好改为show((char*)&a);
【 在 gdl 的大作中提到: 】
: 这……你用的什么编译器,我这里连编译都通不过:'show' : cannot convert parameter 1 from 'int *' to 'unsigned char *'
: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast