For more exciting content, please click the blue text above to follow me!
Continuing from the previous article《C Language Textbook: A Summary of Pointer Applications, Sharing the Differences Between Various Applications, and Unraveling the Mysteries of Pointer Usage(1)》 where we shared part of the content, this article continues.
The table below summarizes the applications of pointers, and today I will continue to share various applications in detail:

4. Functions Returning Pointers (Continuing from the previous section)
As we all know, functions can return values, and we can define a function that returns a pointer type.
In simple terms, a function that returns a pointer is a function whose return result is a memory address (pointer), which points to a specific memory area, where data of a specific type is stored, which can be of type character, integer, long integer, array, or structure, etc..
It may sound complicated, but why do we need such functions? Because these functions have their own advantages, as follows:
1) Dynamic Memory Allocation:
Creating dynamic arrays or objects within the function and returning their addresses to the caller.
2) Handling Large Data:
Avoiding data copying during function calls by directly returning the address of the data, which can improve efficiency.
3) Accessing Global Resources:
Returning the addresses of global variables, static variables, or file handles.
5. Function Pointers
A function pointer is a special type of pointer in C that points not to a variable or an array, but to a function.
In simple terms: a function pointer is a variable that stores the address of a function, allowing it to dynamically call different functions at runtime, making it convenient for software developers to call different functions based on different operations.
Although some people think that these functions are not user-friendly, they are actually widely used without realizing it. For example, in embedded software development, interrupt functions are a very good case; each interrupt has its own entry address, which stores the corresponding interrupt function pointer (address).
The syntax for defining a function pointer is as follows:
return_type (*pointer_name)(parameter_types);
return_type: the return type of the function;
(*pointer_name): the name of the pointer variable, which must be enclosed in parentheses;
parameter_types: the parameter types of the function;
Here is an example of application:
// Define a function pointer
int (*add)(int, int);
// Define a function that matches the pointer
int addNumbers(int a, int b)
{
return (a + b);
}
// Initialize the function pointer to point to the function
add = addNumbers;
// Use the function pointer to call the function, equivalent to callingaddNumbers(3, 4);
int result = add(3, 4);
The table below compares this type of function, which may be difficult for some to understand and requires gradual digestion:

6. Double Pointers (Pointers to Pointers)
There was a dedicated article earlier《Pointers to Pointers, a programming technique that 80% of engineers do not know how to use. Once learned and applied flexibly, every program written using it will become a classic case.》 for your reference.
The table below compares single pointers and double pointers:

——–Author’s Experience—————
Endless Pursuit of Knowledge
Pen name: Chip Knowledge Explorer, years of power research. Alone facing the screen, deep in thought, technical insights flow from the pen. Day and night, diligent writing continues, a month of persistence without idleness. Although the traffic is small, the heart is sweet towards the light. I hope you pay attention to the details, your suggestions will warm my heart. If you find the writing lacking, please let me know directly to help me improve. Likes and shares are all appreciated, following along makes the journey wider. May I keep this path with passion, turning wisdom into poetry.
——————————-
Creating is not easy, thank you for your attention, thank you for your likes, thank you for sharing!
Classic articles from the past:
1. Electric Brother’s Adventures (Serialized) in Guangxi – Yongcheng -> Three Streets and Two Alleys.
2. Differences in Human-Machine Interaction (MMI) Design Between Industrial and Consumer Products, check out my summary!
3. Optimization and Upgrade of Human-Machine Interaction MMI Design, Capacitive Sensing Button Design Replacing Mechanical Button Design.
4. In the embedded operating system uCOS-II, I will share in detail about Intertask Communication.
5. Using Bit Fields and Unions in Microcontroller C Programming, a programming technique that 99% of engineers never think of, especially used in driver programming, I will continue to share today.
Since you are here, please give a thumbs up before you leave.~~~