Item 17. Comparison of functions and array declarations

xiaoxiao2021-03-05  20

Item 17. Dealing with Function and Array Declarators

The function and array statement can be put together, because they have the same experience, the same is the end of the world.

-------------------------------------------------- ---------------- 1, two function declarations, for example: int * f1 (); // Return the type INT * function int (* fp1) (); // pointing Returns the pointer of the function of type INT

2, two arrays, for example: const INT n = 12; int * a1 [n]; // has N INT * array int (* ap1) [n]; // Pointing to a pointer with N INT

3, pushible int (** ap2) [n]; // ptr to Ptr to array of n tent * (* ap3) [n]; // ptr to array of n int * int * int * int * int * int * int * int * int * int ) () = 0; // const PTR to Ptr to funcint * (* fp3) (); // ptr to func That returns int *

4. When the function encounters an array, Int (* AFP2 [N]) (); // array of n ptr to func That Returns Int

Another way to write TypeDef int (* fp) (); // ptr to func That Returns intfp AFP3 [N]; // Array of N fp, Same Type as AFP2

5. After reference and const appear: int Afunc (Double); // Funcint (& RFUNC) (Double) = AFUNC; // Ref to funcint (* const pfunc) (double) = Afunc; // const ptr to func

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

New Post(0)