#include #includenum, p->name, &p->pay) printf(员工信息为:n”) printf("%d %s %0.1f\n", p->num, p->name, p->pay) 释放已申请的空间* p=( struct Worker*) malloc(2+LEN)/*重新申请2个 Worker大小的空间,并用p指向它 printf(“请输入两名工人的编号、名字和工资:Ⅶn”) canf("%d%s%f, &p->num, p->name, &p->pay) canf("%d%S%f, &(p+1)->num, (p+ 1)->name, &(p+1)->pay); printf(员工信息为:n”) printf("%d %s %0. 1f\n",p->num p->name, p->pay); printf("%d %s %0. 1fn",(p+1)-num, (p+1)->name, (p+1)->pay); free(p)
#include #include #define LEN sizeof(struct Worker) struct Worker { int num; char name[20]; float pay; }; main() { int i; struct Worker *p; float f; printf(“请输入一个实型数:”); scanf("%f",&f); p=(struct Worker*)malloc(LEN); printf(“请输入一名工人的编号、名字和工资:\n”); scanf("%d%s%f",&p->num,p->name,&p->pay); printf(“员工信息为:\n”); printf("%d %s %0.1f\n",p->num,p->name,p->pay); free(p); /*释放已申请的空间*/ p=(struct Worker*)malloc(2*LEN);/*重新申请 2 个 Worker 大小的空间,并用 p 指向它 */ printf(“请输入两名工人的编号、名字和工资:\n”); scanf("%d%s%f",&p->num,p->name,&p->pay); scanf("%d%s%f",&(p+1)->num,(p+1)->name,&(p+1)->pay); printf(“员工信息为:\n”); printf("%d %s %0.1f\n",p->num,p->name,p->pay); printf("%d %s %0.1f\n", (p+1)->num,(p+1)->name,(p+1)->pay); free(p); }