f函数出错请看看这程序错在哪里谢谢
#include"stdio.h"#include"malloc.h"
void f(struct arr *j)
{
}
int main(void)
{
struct arr
{
int a;
struct arr *p;
};
struct arr *z,*x;
z=(struct arr*)malloc(sizeof(struct arr));
z->a=1,z->p=x;
f(&z);
return 0;
}
程序代码:#include"stdio.h"
#include"malloc.h"
struct arr
{
int a;
struct arr *p;
};
void f(struct arr *j)
{}
int main(void)
{
struct arr *z, *x;
z=(struct arr*)malloc(sizeof(struct arr));
x=(struct arr*)malloc(sizeof(struct arr));
z->a=1,z->p=x;
f(z);
return 0;
}
最好把程序改成这样, 你不为x分配内存就去使用它,p指针知道x指向的地址在哪里呢,所以这样修改后运行不会出错