回调函数

来源:互联网 发布:卡盟主站源码 编辑:程序博客网 时间:2024/04/30 12:39


#include <stdlib.h>
#include <stdio.h>


int  Test1()
{
 int i;
 
 for (i=0; i<30; i++)  
 {  
  printf("The %d th charactor is: %c\n", i, (char)('a' + i%26));  
    }
 
 return 0; 
}

int Test2(int num)

 int i; 

 for (i=0; i<num; i++)  
 {  
  printf("The %d th charactor is: %c\n", i, (char)('a' + i%26));  
    }
  return 0; 
}

void Caller1(int (*ptr)())//指向函数的指针作函数参数
{
 
 (*ptr)();
 
}
// void Caller2(int n, int (*ptr)())//指向函数的指针作函数参数,这里第一个参数是为指向函数的指针服务的,
// {
//  // //不能写成void Caller2(int (*ptr)(int n)),这样的定义语法错误。
//
//  (*ptr)(n);
//  return;
//
// }
int main()

{
 
 printf("************************\n");
 
 Caller1(Test1); //相当于调用Test2();
 
 printf("&&&&&&************************\n");
  
//  Caller2(30,Test2); //相当于调用Test2(30);
 int j;
 scanf("%d",&j);
 return 0;
 
}

 

原创粉丝点击