当前位置:网站首页>The use of C language typedef 】 : structure, basic data types, and array

The use of C language typedef 】 : structure, basic data types, and array

2022-08-09 11:16:00 XV_

typedef basic data type

typedef int a;a abc;

The following a abc is equivalent to int abc

typedef structure

typedefstruct a {int a;int b;}abc;abc aaa;

For the above, abc aaa; is equivalent to struct a aaa;

In short, the essence of typedef is to build an equivalence relation.

The first example, let a and int be equivalent;
The second example, let abc and struct a { int a; int b; };equivalent;

This simplifies writing .

There are special cases, however, when using arrays.

typedef array

typedef int a[5];a aa;

Here a aa is equivalent to int aa[5], where the essence of aa is array of int type with 5 elements.

That is to say, typedef int a[5];, making a equivalent to int[5], of course, C language does notThis way of writing, I hope to understand, a represents an array with 5 elements of type int.

typedef struct desc_struct{unsigned long a, b;}desc_table[256];desc_table idt, gdt;

Here idt is struct desc_struct idt[256], and the same is true for gdt.

原网站

版权声明
本文为[XV_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091103199367.html