malloc 返回值的操作(请高手指点)
原代码:
typedef struct node
{ int length;
}linklist;
typedef struct
{
linklist *front,*rear;
}linkqueue;
linklist *test;
linkqueue *m;
test=(struct node *)malloc(sizeof(linklist));
m->front=test;
运行出错 引用的内存地址不能written,我的问题是为什么test不能赋予m->front,如何解决?
问题点数:20、回复次数:4Top
1 楼opentuxedo(借哥哥的号来试试)回复于 2002-04-16 22:19:56 得分 10
m分配内存了吗?Top
2 楼JoeXu(我是一个诗人)回复于 2002-04-16 23:07:19 得分 0
simpleTop
3 楼cplusc(5i海洋)回复于 2002-04-16 23:57:32 得分 0
去掉(struct node *)Top
4 楼Lchaos(nicky)回复于 2002-04-17 00:14:25 得分 10
yes, if you didn't allocate memory for m,
m is a wild pointer, of course you will get into error if you reference m.Top




