C語言_結構體變數指標做函式引數的使用案例

OldBoy~發表於2018-01-03
# 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;
    
}

 

相關文章