ArticleDirectory
- Semantic Analysis of C/C ++ complex symbol combinations
Semantic Analysis of C/C ++ complex symbol combinations: Left-right method
Start from the variable, start from the lower right corner, and rotate it counter-clockwise. When () is used as parentheses, there is no need to interpret the delimiters. If it is used as a function, it is interpreted as "a function of the ×× type is returned ".
Instance 1
INT (* pa [10]) (INT, INT );
Analysis result: [] is displayed at the beginning of PA, indicating that PA is an array, which is rotated counterclockwise and X is displayed, indicating that the elements in the array are pointers and parentheses are displayed, continue to rotate, see the function, so this pointer points to the function. The meaning of this pa is an array of 10 function pointers. Use typedef to define this instance. Typedef int (* mytype) (INT, INT); mytype pa [10];
Instance 2
Int * Fun (INT, INT) [10];
Analysis results: Fun, first saw the function, indicating that fun is a function, then saw a pointer, indicating that the function of fun returns a pointer, and then saw an array, the returned pointer is a pointer to a 10-element array. Fun is a function that returns 10 element array pointers. Use typedef to define typedef int * mytype [10]; mytype fun (INT, INT );
Note:
In fact, these complex symbols should not appear frequently during programming.ProgramReadability will become difficult to understand. Basically, typedef is used to define instructions to increase readability. For example, the above two instances can be defined using typedef in the following mode. Program readability is greatly enhanced.
// Typedef of instance 1 implements typedef int (* mytype) (INT, INT); // typedef a function pointer mytype pa [10]; // defines the array of function pointers. // Typedef of instance 2 implements typedef int * mytype [10]; // defines the array pointer mytype fun (INT, INT); // defines the function that returns the array pointer.