7.11typedef关键字

本文介绍了C语言中的typedef关键字,它用于为现有数据类型创建别名,以提高代码可读性和简洁性。示例中展示了如何为无符号字符、短整型和整型定义新的类型名,并用typedef创建了一个名为STU的结构体类型,包含分数、姓名指针和函数指针成员。在主函数中,使用这些新类型进行变量声明和操作,展示了typedef的实际应用。

7.11typedef关键字

介绍并使用typedef关键字

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

	/*	7.11
	author:edcfreedom
	date:2021/8/27
	funDescription:
	typedef
	typedef为c语言的关键字
	作用是为一种数据类型定义一个新名字
	这里的数据类型包括内部数据类型(int,char等)和自定义的数据类型(struct等)
	
	而struct来匹配为了代码编写简洁
	和普通类型匹配,通过名字来获取一些信息
*/

//在单片机开发,寄存器位 8位 16位 32位

//int data = 0x1234;

//char data = 0x11;

//char int double float;

typedef unsigned char u_int8;
typedef unsigned short int u_int16;
typedef unsigned int u_int32;

typedef struct Student
{
	int score;
	char *name;
	void (*p)(struct Student stu);
}STU,*PSTU;//可以给这个结构体取名字


int main()
{
	u_int8 data1 = 10;
	u_int16 data2 = 20;
	u_int32 data3 = 40;
	
	//struct Student stu1;
	STU stu1;//命名为STU
	stu1.score = 100;
	printf("score:%d\n",stu1.score);
	
	PSTU pstu;
	pstu = (PSTU)malloc(sizeof(STU));
	pstu->score = 99;
	printf("score2:%d\n",pstu->score);
	
	struct Student *pstu3;
	pstu3 = (struct Student *)malloc(sizeof(struct Student));
	pstu3->score = 99;
	printf("score3:%d\n",pstu3->score);
	
	printf("%d,%d,%d\n",data1,data2,data3);
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值