结构体类型的创建

结构体类型的创建

#include "stdafx.h"

#if 0
一、有名结构体的俩种定义方式:
(1)定义类型的同时,完成了变量的定义
//struct Student 相当于创建了类型,相当于int
struct Student
{
	char name[100];
	char sex;
	int age;
	float score;
}stu; //既然 struct Student为类型则 stu为变量

(2)先有类型,再声明/定义变量
struct Student
{
	char name[100];
	char sex;
	int age;
	float score;
}
struct Student s;
//优点:一次定义,多处使用,会带来新的命名(提高复杂度)



二、无名结构体
(1)定义类型的同时,完成了变量的定义
struct 
{
	char name[100];
	char sex;
	int age;
	float score;
}stu;
//优点:无名结构体不引入新的类型(降低复杂度)



三、别名结构体
(1)定义结构体类型的别名
typedef struct Student  //加上student方便以后追溯但可以省略
{
	char name[100];
	char sex;
	int age;
	float score;
}STU; //此时的STU为结构体类型的别名,而不为变量

#endif


int _tmain(int argc, _TCHAR* argv[])
{
	//printf("%s\n", s.name);
	//printf("%s\n", s.sex);

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值