C语言中的typedef关键字

The typedef keyword in C allows you to defined new types.

C语言中的typedef关键字允许您定义新类型。

Starting from the built-in C types, we can create our own types, using this syntax:

内置的C类型开始 ,我们可以使用以下语法创建自己的类型:

typedef existingtype NEWTYPE

The new type we create is usually, by convention, uppercase.

按照惯例,我们创建的新类型通常是大写的。

This it to distinguish it more easily, and immediately recognize it as type.

这样可以更容易地区分它,并立即将其识别为类型。

For example we can define a new NUMBER type that is an int:

例如,我们可以定义一个新的NUMBER类型为int

typedef int NUMBER

and once you do so, you can define new NUMBER variables:

然后,您可以定义新的NUMBER变量:

NUMBER one = 1;

Now you might ask: why? Why not just use the built-in type int instead?

现在您可能会问:为什么? 为什么不只使用内置类型int呢?

Well, typedef gets really useful when paired with two things: enumerated types and structures.

好吧,当与两个东西配对时, typedef会变得非常有用:枚举类型和结构。

翻译自: https://flaviocopes.com/c-typedef/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值