~$ 存档

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

第一种情形,普通函数调用。
编译器不知道函数调用地址,直到程序运行时...

#include "stdio.h"
#include "stdlib.h"
typedef void(*Pointer)(const int);
/**********函数***********/
void dec(const int n)/*打印十进制*/
{printf("%d\n",n);}
void oct(const int n)/*打印八进制*/
{printf("%o\n",n);}
void hex(const int n)/*打印十六进制*/
{printf("%x\n",n);}
/************************/
void display(Pointer p,const int n)/*编译器不知道调用哪个函数*/
{
    p(n);
}
int main(int argc,char *argv[])
{
    int n;
    if(argc>1)
    n=atoi(argv[1]);
    display(dec,n);   
    return 0;
}

 

posted on 2016-04-06 08:25  LuoTian  阅读(98)  评论(0)    收藏  举报