C语言用结构体指针作函数参数
例如
struct book
{
char bookname[30];
int quantity;
};
main()
{
void fun(struct book*p);
struct book book1={"Programming in C",10};
fun(&book1);
printf("%d copies\n", book1.quantity);
}
void fun(struct book*p)
{
printf("The book \" %s\" has ",p->bookname);
p->quantity -=3;
}
显示:The book "Programming in C" has 7 copies
此外,还可将结构体数组作为函数参数;还可设计结构体指针型函数,即返回的地址是指向结构体类型数据的。