匿名结构即为没有名字的struct,一般作为其它struct成员使用。
#include <stdio.h>
#include <string.h>
/*
时间:2022-05-13 16:02
作者:sgbl888
功能:匿名结构
知识点:
1、
2、
3、
*/
/* struct conact{
char email[30]; //邮箱
long long phone; //电话号码
}; */
struct Student{
char name[20]; //姓名
short gender; //性别
//struct conact; //匿名结构作为Student成员
struct{ //匿名结构
char email[30]; //邮箱
long long phone; //电话号码
};
};
int main(){
struct Student st1;
strcpy(st1.name, "李小花");
st1.gender = 2;
strcpy(st1.email, "lixiaohua@163.com");
st1.phone = 13001300123;
printf("姓名:%s\t性别:%hd\t%邮箱:%s\t电话:%lld\n", st1.name, st1.gender, st1.email, st1.phone);
return 0;
}