代码如下:
// struct.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
int g_Con[128] = { 0 };
typedef struct tag_Info_S
{
int num1;
int num2;
double num3;
}Info_S;
int main(int argc, _TCHAR* argv[])
{
Info_S *p = (Info_S *)g_Con; //将int类型的数据强制转换成为Info_s
p->num1 = 0x1;
p->num2 = 0x10;
p->num3 = 0x1234.5678; //由于类型不一致,double在写入int数组的时候会发生数字截断,输出比较奇怪
for (int i = 0; i < 5; i++)
{
printf("g_Con[%d] = %0x\n", i, g_Con[i]);
}
return 0;
}
说明:
对于内存来说是没有类型的。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。