C Language Advanced programming--function pointers

Source: Internet
Author: User

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) () points to a function such as void f (). examples of using function pointers:
void open ();//declaration of several functions void print (); void exit (); void (*pfs[]) () ={open,print,exit};//function pointer array int main () {int i;void (*PF) () ;p F=open; (*PF) ();//////calls open () for (i=0;i<3;i++)////calls open (), print (), exit () function (*pfs[i]) ();} void Open () {printf ("open\n");} void print () {printf ("print\n");} void exit () {printf ("exit\n");}
As you can see from this example, the function name itself is the address of the function code area.There are several definitions that are confusing, consider the following definitions:
void (*getinterrupt (int No)) (), void setinterrupt (int no,void (*PF)); LRESULT (*lpfnwndproc) (Hwnd,unit,wparm,lparam);
The first statement indicates that aGetinterrupt's prototype declares that it has an int type parameter, and the return value is a pointer to a void f () function. The second declaration represents a functionSetinterrupt's prototype declaration, the return value is void, it has two parameters, the type is int and a pointer to the void F () function. the third declaration defines a pointer variableLpfnwndproc, pointing shape asthe function of LRESULT WndProc (Hwnd,unit,wparm,lparam).

C Language Advanced programming--function pointers

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.