目录
一、结构体成员为函数指针类型
例如:
struct bingx{
char name[20];
float price;
void (*open)(void);
void (*close)(void);
};
struct elephent{
char name[20];
float weight;
void(*walk)(void);
};
struct person{
int age;
char name[20];
void (*open)(struct bingx bx);
void (*close)(struct bingx bx);
void (*push)(struct elephent el);
};
二、结构体传参
例如:
struct A{
int a;
float b;
};
void fun01(struct A s)
{
printf("%d,%.2f\n",s.a,s.b);
}
void fun02(struct A* p)
{
p->a = 120;
p->b = 45.55;
}
int main(void)
{
struct A st;
fun02(&st); //地址传递
fun01(st); //值传递
return 0;
}
三、函数返回结构体
struct A{
int a;
float b;
};
struct A fun(void)
{
struct A st = {120,22.33};
return st;
}
int main(void)
{
struct A s;
s = fun();
printf("%d,%.2f\n",s.a,s.b);
return 0;
}