c语言typedef 与结构体指针

转载博客:https://blog.csdn.net/developerof/article/details/24885205?utm_source=blogxgwz0



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

typedef struct emp{
 char sex[8];
 char name[15];
 int age;
}*emp;//这里我们用typedef把emp这个结构体变成了*emp这种指向结构体成员的结构体指针

/*typedef struct emp{
 char sex[8];
 char name[15];
 int age;
}pi,*emp;//为了程序的可读性最好不要这样声明*/

int main(){
 emp p;//注意这里emp是指向结构体的指针变量 emp *p这样的声明是错误的,emp p这样声明了结构体类型的指针变量p
 strcpy(p->sex,"male");
 strcpy(p->name,"zhangfei");
 p->age=20;
 printf("sex is %s\n",p->sex);
 printf("name is %s\n",p->name);
 printf("Age is %d\n",p->age);
 return 0;
}

猜你喜欢

转载自blog.csdn.net/songsong2017/article/details/83303936