The difference between a pointer function and a function pointer

Source: Internet
Author: User

"-" Turn from: http://www.cnblogs.com/gmh915/archive/2010/06/11/1756067.html

The use of the second function pointer:

Form 1: Return type (* function name) (parameter table)

 1  char  (*pfun) (int  );  2  char  glfun (int  a) {return   3  void   main ()  4  5    pfun = Glfun;  6  (*pfun) (2  );  7 } 

The first line defines a pointer variable pfun. First we recognize that it is a pointer to a function, according to the "Form 1" mentioned earlier, which is an int and the return value is a char type. Only the first sentence we can not use this pointer, because we have not yet assigned to it.
The second line defines a function glfun (). The function is exactly a function that returns char as an int parameter. We are going to understand the function from the level of the pointer-the function name of the function is actually a pointer, and the function name points to the first address of the function's code in memory
Then there is the main () function, and the first sentence you should understand-it assigns the address of the function Glfun to the variable pfun. The "*pfun" in the second sentence of the main () function is clearly the content of the address pointed to by Pfun, and of course the contents of the function Glfun () are taken out, and the given parameter is 2.

The difference between a pointer function and a function pointer

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.