Callback function,

Source: Internet
Author: User

Callback function,

 1 #include <stdio.h>   2    3 void PrintNum1(int n); 4 void PrintNum2(int n); 5 void ShowNum(int n, void (* ptr)(int));   6    7 void PrintMessage1();   8 void PrintMessage2();   9 void PrintMessage3();  10 void ShowMessage(void (* ptr)());  11   12 int main(){  13    ShowNum(11111, PrintNum1);  14    ShowNum(22222, PrintNum2);  15    ShowMessage(PrintMessage1);  16    ShowMessage(PrintMessage2);  17    ShowMessage(PrintMessage3);  18 }  19   20 void PrintNum1(int n){  21    printf("Test1 is called,the number is %d\n", n);  22 }23 24 void PrintNum2(int n){  25    printf("Test2 is called,the number is %d\n", n);  26 }   27   28 void ShowNum(int n, void (* ptr)()){  29    (* ptr)(n);  30 }  31   32   33 void PrintMessage1(){  34    printf("This is the message 1!\n");  35 }  36   37 void PrintMessage2(){  38    printf("This is the message 2!\n");  39 }  40   41 void PrintMessage3(){  42    printf("This is the message 3!\n");  43 }  44   45 void ShowMessage(void (* ptr)()){  46     (* ptr)();  47 }  

 

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.