Getting started with iOS development☞C language (Advanced pointer, judgment type), ios pointer
Advanced pointer
Advanced pointers: including double pointers (second-level pointers), void pointers, and function pointers.
1. Double pointer
A double pointer (second-level pointer) is a pointer of a pointer.
2. void pointer
Void pointer: a universal pointer that represents any type of pointer.
When malloc allocates heap memory, the memory storage type cannot be determined, so void * can be used to represent any pointer type.
3. function pointer
- A function pointer is a pointer variable pointing to a function. Each function has an entry address. The entry address of the function is saved in the pointer variable.
- Each function has an entry address, which is the address pointed to by the function pointer. With the pointer variable pointing to the function, you can use the pointer variable to call the function, just as you can use the pointer variable to reference other types of variables.
- Function pointers have two purposes: Calling functions and making function parameters.
Function pointer declaration method:
Return Value Type (* pointer variable name) ([parameter list]);
Definition Format of function pointer (pointer to function:
A function also occupies a storage space, because the function also occupies a storage space, so the function also has its own address.
The function address is saved in the function name. The function name is the function address = the array name is the array address.
The array name is the constant pointer pointing to the first element of the array, and the function name is also the constant pointer pointing to the first instruction of the function.
Syntax format of the function pointer:
Advantages and disadvantages of function pointers:
- Advantage: if another function is used in a common function, but the function name is not fixed, it is compiled by the user. In this case, the function pointer must be used.
For example, for general point calculation, the computed function is to be determined by the caller.
For example, the general sorting function is also used, and the comparison function and the exchange function are also compiled by the user.
- Disadvantage: The program crashes easily because the function pointer points to is not fixed.
Judgment type
How to determine the type: from the right to the left, without parentheses, you can see what type is on the far right. With parentheses, you can see what type is on the right.
The difference between a function and a method: a function is owned by everyone and has no class. Methods are class-based and not all users can use them.