指针问题
#include <stdio.h>#include <stdlib.h>
struct base {
int x;
int y;
};
struct inhert {
struct base *base;
int pri_i;
int pri_j;
};
int main(void)
{
struct base *base = (struct base *)malloc(sizeof(struct base));
struct inhert *inhert = (struct inhert *)base;
inhert->pri_i = 1;
printf("%d", inhert->pri_i);
free(base);
inhert = NULL;
return 0;
}
为什么这个程序不会报错,因为base的空间的首地址给了inhert,而inhert操作的空间已经大于了base申请的空间。为什么不会报错呢?