An answer to the C function pointer

Source: Internet
Author: User
The biggest use of a function pointer is that it can be called by a template method, which I learned when learning the Java design pattern. for example, two functions have the same process structure, but the specific functions called internally are different, as shown in the following figure: void func1 () {// a process Code And Aspect-Oriented proxy, such as security check and logging int sum = add (x, y); // a piece of Process Code and Aspect-Oriented proxy, such as security check, log Record, etc.} void func2 () {// a piece of Process Code exactly the same as func1 and an aspect-oriented proxy, such as int Difference = sub (X, y); // a piece of Process Code exactly the same as func1 and an aspect-oriented proxy, such as security check and logging}. Then, you can define only one function, void func (pfunc p) {// Process Code and Aspect-Oriented proxy exactly the same as func1, such as int Difference = p (x, y); // a piece of Process Code exactly the same as func1 and an aspect-oriented proxy, such as security check and logging} call Program During the call, let the parameter P point to the ADD and sub functions, respectively. For other questions, since the focus of my writing and work is no longer at all C Language I have no time to answer questions one by one. I will use the answers released by jackie214 to respond to you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.