指向数组的指针(不是数组指针)是C编程语言的一个鲜为人知的特性.
int arr[] = { 3, 5, 6, 7, 9 };
int (*arr_ptr)[5] = &arr;
printf("[2]=%d", (*arr_ptr)[2]);
They allow you to "un-decay" a dynamically allocated array pointer.
(which is pretty cool in my opinion)
int *ptr = malloc(sizeof(int) * 5);
int(*arr_ptr)[5] = (int(*)[5])ptr;
printf("[2]=%d", (*arr_ptr)[2]);
I'm trying to define a function to return an array pointer, without success.
I tried something like this:
int (*)[5] create_arr_5(void)
{
int(*arr_ptr)[5] = malloc(sizeof(int) * 5);
return arr_ptr;
}