(4) parse the C statement
Before continuing to explore the C pointer, it is necessary to parse the complex declaration syntax in the C language.
You only need to remember two points: one principle and one rule.
Principle: first look at the identifier.
Rule: The operator priority is a rule.
Example
1. The simplest int array [3];
Conclusion: array is an array, array size is 3, and element type is int.
Parsing process: first look at the identifier: array, there is only one operator [], then the array is an array, the element type is int, it is complete.
2. Difficult
(1) array pointer int (* array) [3];
Conclusion: array is a pointer pointing to an array with a size of 3 and an element type int in the array.
Parsing process: first look at the identifier: array. Because the brackets operator is used, it can only be parsed (* array) First, indicating that array is a pointer. If the parsing is complete, you can discard it. Then only [] is left, indicating that it is directed to an array, and the rest is not explained.
(2) pointer array int * array [3];
Conclusion: array is an array with a size of 3 and the element type in the array is int *.
Parsing process: first look at the identifier: array. Because [] has a higher priority than *, array first combines with [], indicating that array is an array. Only one X is left, indicating that the pointer is stored in the array. The Pointer Points to an int type, that is, the element type in the array is int *.
It seems that the difference is only one (), meaning completely different.
Memory of array pointers and pointer Arrays:
3. More complicated
Function pointer int (* pfun) (INT, INT );
Conclusion: pfun is a function pointer, that is, pfun points to a function. This function has two parameters: int and INT, And the return value of the function is int.
Parsing process: first look at the identifier: pfun. Because the brackets operator is used, it can only be parsed first (* pfun). This indicates that pfun is a pointer. Now only (INT, INT) is left. It is further explained that pfun is pointing to a function. This function has two parameters, the type is int, and the final int indicates that the return value type of the function is int.
4. More complex
Int * (* pfun [3]) (INT, void (*) (INT, int *));
Whether you are dazzled or not. Using the above method, you will parse it. You may wish to write it in the comments for a comparison.
Column Directory: C pointer