结构体之间的强制类型转换

来源:互联网 发布:python字符串转换列表 编辑:程序博客网 时间:2024/06/06 09:35

 

测试代码:

#include <stdio.h>struct A{int num;};struct B{int num;char type;int age;};int main(void){struct A a;a.num = 1;char* temp1 = (char*)(&(a.num));temp1 = temp1 + 4;*temp1 = 'a';int* temp2 = (int*)(&(a.num));temp2 = temp2 + 2;*temp2 = 100;struct B* b = (struct B*)(&a);printf("b->num=%d b->type=%c b->age=%d\n",        b->num, b->type, b->age);         return 0;}


 

原创粉丝点击