C language advanced programming-function pointer

Source: Internet
Author: User

C language advanced programming-function pointer
The function pointer points to the code area, and the normal Pointer Points to the data area. The function pointer is defined as follows:Return type (* function pointer variable) (parameter table)For example, void (* pf) () refers to a function like void f. Example of using function pointers:

Void open (); // declare void print (); void exit (); void (* pfs []) () = {open, print, exit} for several functions }; // function pointer array int main () {int I; void (* pf) (); pf = open; (* pf )(); ///// call open () for (I = 0; I <3; I ++) // call open () and print () in sequence (), exit () function (* pfs [I]) ();} void open () {printf ("open \ n");} void print () {printf ("print \ n");} void exit () {printf ("exit \ n ");}
From this example, we can see that the function name itself is the address of the function code area. There are several confusing definitions. Consider the following:
Void (* getInterrupt (int no) (); void setInterrupt (int no, void (* pf); LRESULT (* lpfnWndProc) (HWND, UNIT, WPARM, LPARAM );
The first declaration indicates the prototype declaration of getInterrupt. It has an int type parameter, and the return value is a pointer similar to void f () function. Actually, after getInterrupt (int no) is run, it is the return value of this function. the second declaration indicates the prototype declaration of the setInterrupt function. The return value is void, which has two parameters, the int type and the pointer to the void f () function. The third Declaration defines a pointer variable lpfnWndProc, which refers to a function in the shape of LRESULT wndproc (HWND, UNIT, WPARM, LPARAM.

Related Article

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.