关于结构体强制类型转换问题
#include<stdio.h>#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct examp_1
{
int a;
char b;
char c[10];
};
struct examp_2
{
int a;
char b;
char *c;
};
main()
{
examp_1 *y;
examp_2 *x;
y=(examp_1 *)malloc(sizeof(struct examp_1));
y->a=2;
y->b='t';
for(int i=0;i<10;i++)
y->c[i]=i+48;
printf("%d\n %c\n %s\n",y->a,y->b,y->c);
getch();
x=(struct examp_2 *)y; //这里强制类型转换错误 ,程序运行到这就终止了,我查了百度,好像就是这么做的,麻烦帮我看下
printf("after:\n%d\n %c\n %s\n",&x->a,&x->b,x->c);
}