下面的声明有什么区别:
int* arr1[8];
int (*arr2)[8];
int *(arr3[8]);
理解更复杂的声明的一般规则是什么?
发布于 2009-05-13 18:37:30
int* arr[8]; // An array of int pointers.
int (*arr)[8]; // A pointer to an array of integers
第三个与第一个相同。
一般规则是operator precedence。随着函数指针的出现,它可能会变得更加复杂。
发布于 2009-05-13 18:45:00
按照K&R的建议,使用cdecl程序。
$ cdecl
Type `help' or `?' for help
cdecl> explain int* arr1[8];
declare arr1 as array 8 of pointer to int
cdecl> explain int (*arr2)[8]
declare arr2 as pointer to array 8 of int
cdecl> explain int *(arr3[8])
declare arr3 as array 8 of pointer to int
cdecl>
它也以另一种方式工作。
cdecl> declare x as pointer to function(void) returning pointer to float
float *(*x)(void )
发布于 2011-03-02 16:03:19
int *a[4]; // Array of 4 pointers to int
int (*a)[4]; //a is a pointer to an integer array of size 4
int (*a[8])[5]; //a is an array of pointers to integer array of size 5
https://stackoverflow.com/questions/859634
复制相似问题