C语言—typedef

typedef给数据类型起一个别名;

#include <stdio.h>

typedef int INTEGER;
int main()
{
	integer a = 100;
	printf("%d", a);
}

typedef int INTEGER;给数据类型int起了一个别名叫做INTEGER,int和INTEGER就是相同的数据类型;

#include <stdio.h>

typedef int INTEGER;
typedef int* PTRINT;
int main()
{
	INTEGER a = 100;
	PTRINT b = &a;
	printf("%d", *b);
}

typedef int* PTRINT;给int指针类型起个别名PTRINT;

在定义PTRINT b = &a;的时候,等价与 int* b = &a;

typedef用来给变量起一个更容易记住的或意义明确的别名;还可以用来简化复杂的类型声明;

#include <stdio.h>

typedef int (*PTR_INT_ARR)[3];
int main()
{
	int arr[3] = { 1,2,3 };
	PTR_INT_ARR ptr_int_arr = &arr;
	for (int i = 0; i < 3; i++)
	{
		printf("%d\n", (* ptr_int_arr)[i]);
	}
}

typedef int (*PTR_INT_ARR)[3]; int类型的指针数组,别名PTR_INT_ARR,指向一个拥有3个整型数据的数组;

#include <stdio.h>

typedef void (*PTR_TO_FUC)(void);

void fuc(void)
{
	printf("Hello");
}
int main()
{
	PTR_TO_FUC ptr_to_fuc = fuc;
	ptr_to_fuc();
}

typedef void (*PTR_TO_FUC)(void);无参无返回值的函数指针,别名为PTR_TO_FUC;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值