zoukankan      html  css  js  c++  java
  • 回调函数理解实例

    // callback.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <stdio.h>
     
    void printWelcome(int len)
    {
           printf("欢迎欢迎 -- %d
    ", len);
    }
     
    void printGoodbye(int len)
    {
           printf("送客送客 -- %d
    ", len);
    }
     
    void callback(int times, void (* print)(int))
    {
           int i;
           for (i = 0; i < times; ++i)
           {
                  print(i);
           }
           printf("
    我不知道你是迎客还是送客!
    
    ");
    }
    void main(void)
    {
           callback(10, printWelcome);
           callback(10, printGoodbye);
           printWelcome(5);
           getchar();
    }

    乱翻的时候看到这段代码,对于理解回调函数十分有效。

    不扯系统函数,不扯dll,例子中callback中调用了printWelcome函数。这就是回调函数。不要想的太深,等遇到实际情况的时候你想想例子,原来就是这么回事。

  • 相关阅读:
    javascript 冒泡
    js闭包
    loadmore & scroll
    viewport
    担当
    javascript pattern
    javascript function
    interview
    json and .net
    java sqlserver
  • 原文地址:https://www.cnblogs.com/lcamry/p/6899585.html
Copyright © 2011-2022 走看看