【发布时间】:2009-06-22 06:27:31
【问题描述】:
以下代码运行成功...
typedef struct _s
{
int *r;
}s;
void main()
{
s *u;
int y=1000;
u=malloc(sizeof(s)*8);
u->r=malloc(sizeof(int)*8);
u->r[5]=y;
printf("%d\n",u->r[5]);
getch();
}
但我如上编写以下代码 但给出错误....我使用结构......为什么我知道原因......? 如果我使用像 (...e **h...) 这样的双指针会产生正确的输出...但原因是...?
typedef struct _e
{
int r;
}e;
typedef struct _s
{
e *h;
}s;
void main()
{
s *u;
int y=1000;
u=malloc(sizeof(s)*8);
u->h=(e*)malloc(sizeof(e)*10);
u->h[1]=y;
printf("%d\n",u->h[1]);
getch();
}
【问题讨论】: