zoukankan      html  css  js  c++  java
  • 一维函数指针数组和二维函数指针数组demo

    #include<stdio.h>
    
    static int add(int a,int b);
    static int sub(int a,int b);
    static int mul(int a,int b);
    static int div(int a,int b);
    static int abs(int a,int b);
    static int mor_mul(int a,int b);
    
    int add(int a,int b)
    {
    	return (a+b);
    }
    
    int sub(int a,int b)
    {
    	return (a-b);
    }
    
    int mul(int a,int b)
    {
    	return (a*b);
    }
    
    int div(int a,int b)
    {
    	return (a/b);
    }
    
    int abs(int a,int b)
    {
    	return a>b?(a-b):(b-a); 
    }
    
    int mor_mul(int a,int b)
    {
    	int value=1;
    	for(;b>0;b--) value=value*a;
    	return value;
    }
    
    static int (*choose_table[6])(int a,int b) = {add,sub,mul,div,abs,mor_mul};
    
    static int (*two_choose_table[2][3])(int a,int b)=
    {
    	{add,sub,mul},
    	{div,abs,mor_mul}
    };
    
    int main()
    {
    	int get_value=(*choose_table[0])(1,2); 
    	printf("get_value is %d\n",get_value);
    	
    	choose_table[0]=sub;
    	get_value=(*choose_table[0])(1,2); 
    	printf("get_value is %d\n",get_value);
    	
    	choose_table[0]=mul;
    	get_value=(*choose_table[0])(1,2); 
    	printf("get_value is %d\n",get_value);
    	
    	get_value=(*choose_table[1])(1,2); 
    	printf("get_value is %d\n",get_value);
    	
    	get_value=(*two_choose_table[1][2])(2,3); 
    	printf("get_value is %d\n",get_value);
    	
    	two_choose_table[1][2] = abs;
    	get_value=(*two_choose_table[1][2])(2,3); 
    	printf("get_value is %d\n",get_value);
    } 
    
    
  • 相关阅读:
    网恋现代人的童话
    男人爱女人
    在Web页面中管理服务
    wcf使用入门学习笔记
    table显示细线边框
    wcf整理资料
    启动sqlserver服务的时候报错
    命名规范
    .net中使用xsl文件作为导航菜单
    wcf如何选择绑定
  • 原文地址:https://www.cnblogs.com/ligei/p/15719607.html
Copyright © 2011-2022 走看看