当将整数指针转换为char指针时,实际发生了什么? [英] What actually happens when a pointer to integer is cast to a pointer to char?

查看:45
本文介绍了当将整数指针转换为char指针时,实际发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int i=40;
char *p;
p=(char *)&i;//What actually happens here?
printf("%d",*p);

输出是什么?请帮忙!

推荐答案

p=(char *)&i;//What actually happens here?

它获取 i 的地址,并将其强制转换为 char 指针.因此, * p 的值现在是 i 的第一个字节.该值是什么,取决于平台.

It takes the address of i and casts it to a char pointer. So the value of *p is now the first byte of i. What that value is, is platform dependent.

这篇关于当将整数指针转换为char指针时,实际发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆