通过结构体指针传参2020-01-23

2020-01-23  本文已影响0人  宜居远控

#include <stdio.h>

#include <string.h>

int input(struct student *pst);

int output(struct student *pst);

typedef struct student //定义了一个结构体数据类型

{

  int num;

  char name[50];

  int age;

};

int main(void)

{

  student st;

  input(&st);

  output(&st);

}

int input(struct student *pst)

{

  pst->num=88;

  strcpy(pst->name,"guo");//字符串赋值用strcpy 不能直接赋值

  pst->age =16;

  return 0;

}

int output(struct student *pst)

{

printf("%d %s %d \n",pst->num ,pst->name ,pst->age );

return 0;

}

上一篇 下一篇

猜你喜欢

热点阅读