结构体指针变量作为函数参数的传递

发布时间:2019-06-11编辑:佚名阅读(1136)

#include <stdio.h>
#include <string.h>
 
struct student {
    int age;
    char sex;
    char name[30];
};
 
void inputstudent(struct student *ps)//对结构体变量输入时必须传地址
{
    (*ps).age = 10;
    strcpy(ps->name, "张三");
    ps->sex = 'f';
}
 
void outputstudent(struct student *ps)//对结构体变量输出时,可传地址也可传内容,但为了减少内存耗费,提高运行速度,建议使用传值
{
    printf("%d %c %s\n", ps->age, ps->sex, ps->name);
}
int main()
{
    struct student st;
    inputstudent(&st);
    outputstudent(&st);
    return 0;
}


  关键字:结构体指针变量函数参数传递C语言


鼓掌

0

正能量

0

0

呵呵

0


评论区