Complex statement and definition

xiaoxiao2021-03-05  35

First look at a simple example: void (* funcptr) (); When seeing such a definition, the best processing method is starting from the middle and outward extension and the mouth of the braces. The meaning of "starting from the middle" is starting from the variable name. The "outward expansion" means to pay attention to the nearest item on the right, and the bracket changes, so continuous. "Digal Brand Braces" refers to the return value of its function (function declaration only) of its function (function declaration only) of its function (function declaration). The above analysis is as follows: The middle begins ----> Funcptr to the right ------> Dragonfly steering --------> Meet *, Funcptr is a pointer, but also parentheses steering ---- ----> An empty parameter table (function without parameters) go left ------> Void Return Value ------> void final result is: Funcptr is a pointer, it points to one With parameters and return VOID functions. Look at a few more complex: void * (* (* fp1) (int)) [10]; FP1 is a pointer to the function, it accepts an int parameter and returns a pointer to the array of 10 VOID pointers ( Void * [10]). Float (* (* fp2) (int, int, float)) (int); fp2 is a pointer to the function, it accepts three parameters: int, int, float and return a pointer to the function, which has one INT parameter and returns a float. TYPEDEF DOUBLE (* (* (* fp3) ()) [10]) (); // The return value is: double (* (*) [10]) (); fp3 a; fp3 is a pointer to the function, This function is no parameter and returns a pointer to 10 pointing function pointer arrays, which does not accept parameters and return Double values. Int (* (* f4 ()) [10]) (); // return value INT (* ([10])) (); f4 is a function that returns a pointer, the pointer points to an array containing 10 function pointers, which returns an integer value. Summary: We may even never use this Complex statements and definitions, but if you can figure it out through exercises, you will not be confused in a slightly complex situation that may be encountered in real life! Reference: <

>

转载请注明原文地址:https://www.9cbs.com/read-34427.html

New Post(0)