结构体作为参数,要加&,子函数的结构体参数加*
例1:
struct st{
int a;
};
int main()
{
struct st t;
f(&t);
ff(&t);
return 0;
}
int f(struct st *t)
{
t->a=100;
}
int ff(struct st *t)
{
printf("%d\n",t->a);
return 1;
}
例2:
int main()
{
struct ss *t;
f(&t);
printf("main:%d\n",t->a);
ff(&t);
return 1;
}
int f(struct ss **t)
{
(*t)=(struct ss *)malloc(sizeof(t));
(*t)->a=100;
}
int ff(struct ss **t )
{
printf("%d\n",(*t)->a);
}
本文详细解析了在C语言中如何使用结构体进行参数传递,包括直接传递结构体指针和传递结构体指针的地址两种方式,并通过具体示例说明了这两种方式的区别及其应用场景。
874

被折叠的 条评论
为什么被折叠?



