导航:首页 > 编程语言 > 编程结构体变量定义

编程结构体变量定义

发布时间:2025-02-09 16:48:08

❶ 什么是结构体变量

结构体变量简称为结构变量,它由结构类型定义,有三种定义方法。下面以定义结构类型 book 和结构变量mybook 、 storybook 为例说明之。
1. 先定义结构类型,再定义结构变量。
struct book /* 定义结构体类型 */
{
char bookname[20];
float price;
char publisher[20];
char author[10];
} ;
struct book mybook, storybook;
用这种方法定义结构变量,是最常用的方法,但须注意不能省略关键字“ struct ”。还可以在定义结构变量的同时给它的成员赋初值。如:
struct book /* 定义结构体类型 */
{
char bookname[20];
float price;
char publisher[20];
char author[10];
} ;
struct book mybook = { “maths”, 24.7, “ 电子社 ”, “zhao” }, storybook;
则, mybook 变量的 price = 24.7 。
2. 定义结构类型的同时定义结构变量。
struct book /* 定义结构体类型 */
{
char bookname[20];
float price;
char publisher[20];
char author[10];
} struct book mybook, storybook;
3. 不定义结构类型,直接定义结构变量。
struct /* 不定义结构类型名 */
{
char bookname[20];
float price;
char publisher[20];
char author[10];
} struct book mybook, storybook;
需要说明的是,当某结构类型的成员又是另外一个结构类型时,称嵌套定义,其定义方法如下:
struct brith_date
{
int month ;
int day ;
int year ;
} ;
struct
{
char name[10] ;
char address[30];
char tel[12];
int age;
struct data birthday;
char sex[3];
} student_01 , employee ;
此例直接定义了 student_01 和 employee 两个变量,但是没有定义此结构体的名字,因此不能再定义与student_01 和 employee 同类的其它结构变量了!如下行定义是错误的:
truct boy, girl;

阅读全文

与编程结构体变量定义相关的资料

热点内容
java窗体按钮 浏览:672
一份程序员情书 浏览:629
69算法怎么测男女 浏览:857
腾讯云企业云服务器多少钱 浏览:5
程序员摆地摊弹唱 浏览:373
本田App怎么连接爱车 浏览:777
男士买衣服在哪个app实惠 浏览:692
安卓车机怎么颜色反转 浏览:903
手机uc下载的文件夹 浏览:966
程序员评论南京 浏览:90
冠道怎么连接安卓车载 浏览:320
手机怎么把两张图片做成文件夹 浏览:724
抖音导出表格发货加密 浏览:135
自己电脑怎么模拟成服务器 浏览:555
单片机的Vpp是 浏览:353
iua编译器下载官方 浏览:87
压缩机高低压快速平衡 浏览:876
phpai 浏览:711
怎么不被命令 浏览:88
大话缘定三生服务器什么便宜 浏览:968