其他分享
首页 > 其他分享> > C语言_结构体变量指针做函数参数的使用案例

C语言_结构体变量指针做函数参数的使用案例

作者:互联网

# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <malloc.h>


//创建一个结构体
typedef struct programmer
{
    int salary;
    int experience;
    char type[15]; 
    
} Programmer;

void OneyearLater(Programmer *);
int main ()
{
    Programmer p = {15000, 3, "PHP"};
    printf("岗位:%s\n当前薪资:%-5d\n当前经验:%d年\n",p.type, p.salary, p.experience);
    OneyearLater(&p);
    printf("------------------一年后---------------------\n");
      printf("岗位:%s\n当前薪资:%-5d\n当前经验:%d年\n",p.type, p.salary, p.experience);
       
    return 0;
}
//一年后 
void OneyearLater(Programmer *p)
{
    p->salary = 18000;
    p->experience = 4;
    
}

 

标签:salary,int,OneyearLater,experience,C语言,函数参数,Programmer,include,指针
来源: https://blog.51cto.com/u_15230485/2821242