Difference between char *[] and char (*)[]
arrays, c, char, pointers
Solution
When trying to interpret C's types, switch the [...] (or group of [...][...]...) with the thing to its left, then read right to left. Thus
char *array[10] -> char *[10]array =
"`array` is an array of 10 pointers to char"
And
char (*array)[10] -> char [10](*array)
"`array` is a pointer to an array of 10 chars"
So in the first case, `array` is 10 contiguous pointers, each of which points to a char (which might be a single char, or a sequence of chars such as a string), whereas in the second case, `array` is a single pointer, to an array of 10 contiguous chars.
You can do something similar with function types, switching the parameter list with the thing to its left. For example,
char* (*f[10])(int*) -> char* (int*)(*[10]f)
"`f` is an array of 10 pointers to functions taking a pointer to int argument and returning a pointer to char".
Problem
What is the difference between `char *array[10];` and `char (*array)[10];` ? By my understanding, - Case 1: - `array` is declared as an array of character arrays of size 10. - This is because `[]` has higher precedence than `*`. - Case 2: - `array` is declared as a pointer to a character array of size 10. - This is because `()` and `[]` have the same precedence and they are evaluated from left-to-right. Then the `*` operator is evaluated. Is my understanding correct? Even if it is correct, I get incredibly confused. Can someone please explain the difference a little more clearly?