常见的typedef用法总结

来源:互联网 发布:传淘宝需要注意什么 编辑:程序博客网 时间:2024/06/07 03:17

常见的typedef用法总结:


首先总而言之typedef的用法就是给一种类型再起另外一个别名

1.常规变量类型


比如:typedef unsigned int uint;


效果:uchar 等价于unsigned char
    uchar c等价于unsigned char c


2.数组类型


比如:typedef int array[M];


效果:array 等价于 int [M]

    array a 等价于 int a[M]


二维数组以及多维数组同理


3.普通指针类型


比如:typedef int * point;


效果:point 等价于 int *

    point p 等价于 int * a


和数组结合起来的话:即指针数组类型


比如:typedef int * point[M];


效果:point 等价于 int * [M]
    point p 等价于 int * a[M]


4.函数类型


比如:typedef int func(void);  


效果:func 等价于 "返回值是int类型、参数为void的函数"类型


即:  func f 等价于 int f(void)


5.函数指针类型


比如:typedef int (*func)(void)


效果:func 等价于 指向"返回值是int类型、参数为void的函数"的指针类型


即:  func pf 等价于int (*pf)(void)  //其中pf是一个函数指针变量,它指向符合返回值是int类型、参数为void类型的函数


1 0
原创粉丝点击