返回的结构体指针,就可以修改这个指针对应的变量;
#include <stdio.h>
#include <stdlib.h>
#include "string.h"
typedef struct tagSTUDENT
{
int id;
char name[50];
}ST;
ST* CreateStuent();
int main()
{ int id=0;;
ST* s1; //这里定义一个指针
s1 = CreateStuent(); //返回一个结构体指针
printf("编号:%d %s\n",s1->id,s1->name);//使用这个指针
printf("请输入新编号:");
scanf("%d", &id);
s1->id = id;//修改这个指针对应的变量
printf("新的编号:%d %s\n",s1->id,s1->name);
delete s1;
return 0;
}
ST* CreateStuent()
{
ST* s1;
s1 = (ST*)malloc(sizeof(ST));
s1->id = 100;
strcpy(s1->name,"hello killty");
return s1;
}