functions and pointers

1 What is a function

A function is a set of C language, in order to perform a specific function that will be reused. Code reuse can be achieved very well with functions.

2 What is a pointer variable

A pointer is an address, and a variable has a storage space. A pointer variable is a variable that stores an address, abbreviated as a pointer. Through the pointer, the memory unit with its address can be found.

Likewise, a variable pointer is the variable address.

3 What is an array 

Array is an important data type in C language and belongs to structural structure. An array is a collection of variables with the same data type and arranged in a certain order. These variables that make up an array are called array elements.

The array has a uniform name called the array name, and the array is classified into one-dimensional array, two-dimensional array, and multi-dimensional array according to the number of subscripts.

For example: int arr[10]={0};

4 What is an array of pointers 

An array of pointers is an array and each member of the array is a pointer.

例如:char*ar'r[5]={"li","zhang","chen","wang","he"};

Since the priority of [ ] is greater than *, arr is first combined with [ ] and then with *. The above example defines a pointer array arr to store names, arr has 5 pointer elements, each pointer points to the beginning of the string address.

5 What is an array pointer

An array pointer is a pointer to an array that points to the first address of an array element.

For example int(*p)[10] is a pointer to 10 elements

6 Function pointers 

A pointer function is a pointer to a function that points to the address of the function.

Definition: int(*fun)(int x, int y); //declare function pointer fun

7 Array of function pointers

   An array of function pointers is an array that can be defined in two ways

     1) First define the array int arr[ ];

           Re-define the pointer array int *arr[ ];

          Finally define an array of function pointers int (*arr[ ] )(int x, int y );

    2) Using typedef as an aid, declare a function pointer array type named arr

          typedef  int(*arr[ ] )( int  ,int );

          Then use this type to define a function pointer array variable and initialize it

          arr af={function body}; 

8 pointer to array of function pointers 

the pointer points to an array of function pointers

Definition: void(*(arr)[ ] )( );

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325528215&siteId=291194637