结构

结构:一种构造的数据类型

声明结构一般形式:

struct 结构类型名

{

         成员表

};

struct StudentType

{

         intnum;

         char*name;

         charsex[3];

         floatscore;

};

结构类型变量的定义

1:先声明再定义

struct 结构类型名

{

         成员表

};

struct 结构类型名 结构变量表;

struct StudentType

{

         intnum;

         char*name;

         charsex[3];

         floatscore;

};

struct StudentType boy,girl;

struct StudentType student[3];//定义结构类型数组

2:先声明的同时定义

struct 结构类型名

{

         成员表;

}结构变量表;

struct StudentType

{

         intnum;

         char*name;

         charsex[3];

         floatscore;

}boy,girl;//student[3],结构类型数组

 

3:直接定义

struct

 

{

         成员表

}结构变量表;

struct

{

         intnum;

         char*name;

         charsex[3];

         floatscore;

}boy,girl;//student[3];结构类型数组。

嵌套的结构类型

struct DateType

{

         intyear;

         intmonth;

         intday;

 

};

struct StudentType

{

         intnum;

         char*name;

         charsex[3];

         structDateType birthday;

         floatscore;

}boy,girl;

结构类型变量可定义时直接初始化

struct StudentType student=

{

         1010;

         “德华”;

         “男”;

{1993,6,18};

         99.8;

};

指针访问结构类型变量各个成员

(*结构类型指针变量).成员名

结构指针变量->成员名

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值