How can I correctly initialize an array pointer in C
Here is my code
int (*data[10]); int a[10]; data = &a[0]; /* gives a warning "int *" cannot be assigned to entity of "int (*)[10]" */
How can I get rid of this warning?
Correctly declare a pointer to an array:
int (*data)[10];
Assign to a pointer to an array:
int a[10]; data = &a;
I believe your brackets are wrong. You need:
Please note that you can use cdecl.org to get help with this.
Your source code says:
declare data as an array of 10 pointers to int
In my opinion it says:
declare data as a pointer to array 10 of int
The data variable is an array of a pointer, and you are trying to assign one pointer to it. If you want to declare data as a pointer to an array, you need to reorder the brackets:
data
I recommend that you read the rule clockwise / spiral .
int **data; int a[10]; data = &a;
you can define data as others: int (*date)[10];but I believe that using it as a double pointer will make more session that day when you want to resize this array from 10 to everything else!
int (*date)[10];