{"rsdb":{"rid":"156008","subhead":"","postdate":"0","aid":"117114","fid":"45","uid":"1","topic":"1","content":"
\n

C\u8bed\u8a00<\/a>\u7684\u51fd\u6570\u6307\u9488\u6570\u7ec4\uff1a<\/strong>\u6982\u5ff5\uff1a\u6570\u7ec4\u5143\u7d20\u662f\u6307\u9488\u51fd\u6570\u7684\u6570\u7ec4\u53eb\u505a\u6307\u9488\u51fd\u6570\u6570\u7ec4\uff0c\u901a\u5e38\u6211\u4eec\u4e5f\u53eb\u505a\u8f6c\u79fb\u8868\u5b9a\u4e49\u4e2a\u521d\u59cb\u5316\uff1a\u8fd4\u56de\u7c7b\u578b\u8bf4\u660e\u7b26 (*\u51fd\u6570\u6307\u9488\u6570\u7ec4\u540d[])(\u53c2\u6570\u5217\u8868) = {\u51fd\u6570\u6307\u9488\/\u51fd\u6570\u540d\uff0c\u2026};\u3002<\/p> \n

\u5982\u4e0b\uff1a int (*fun_array[])(int,int) = {add,del,mul,div};<\/p> \n

\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u4f7f\u7528\u5982\u4e0b\uff1a
\u51fd\u6570\u6307\u9488\u6570\u7ec4\u540d\u4e0b\u6807\u6216\u8005(*\u51fd\u6570\u6307\u9488\u6570\u7ec4\u540d)\u4e0b\u6807\uff1b
\u4e0b\u9762\u662f\u7ed9\u51fa\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p> \n

\r\n#include\n  \n   \r\n\r\nint add(int a,int b); \r\nint sub(int a,int b); \r\nint mul(int a,int b); \r\nint div(int a,int b); \r\nvoid make_menu();\r\n\r\n\r\nint main(int argc,char* argv[]){\r\n    int (*fun_array [])(int,int) = {add,sub,mul,div};\r\n    int cmd = 0;\r\n    int result =  0;  \r\n    int http:\/\/blog.csdn.net\/qq_29924041\/article\/details\/num1,num2;\r\n    while(1){\r\n        make_menu();\r\n        printf(\"please select a num what you want :\");\r\n        scanf(\"%d\",&cmd);\r\n        if(cmd == 0){ \r\n            break;\r\n        }else{\r\n            printf(\"please input two num you want!\\n\");\r\n            scanf(\"%d %d\",&num1,&num2);\r\n            result = fun_array[cmd-1](http:\/\/blog.csdn.net\/qq_29924041\/article\/details\/num1,num2);\r\n            printf(\"the form_1_result you want to calculate is:%d\\n\",result);\r\n            int (*fun_pointer)(int,int) = fun_array[cmd-1];\r\n            result = fun_pointer(http:\/\/blog.csdn.net\/qq_29924041\/article\/details\/num1,num2);\r\n            printf(\"the form_2_result you want to calculate is:%d\\n\",result);\r\n            result = (*fun_array[cmd-1])(http:\/\/blog.csdn.net\/qq_29924041\/article\/details\/num1,num2);\r\n            printf(\"the form_3_result you want to calculate is:%d\\n\",result);\r\n\r\n        }\r\n    }   \r\n    return 0;\r\n}\r\n\r\nint add(int a,int b){ \r\n    return a+b;\r\n}\r\n\r\nint sub(int a,int b){ \r\n    return a - b;\r\n}\r\nint mul(int a,int b){ \r\n    return a * b;\r\n}\r\n\r\nint div(int a,int b){\r\n    return a\/b;\r\n}\r\n\r\n\r\n\r\n\r\nvoid make_menu(){\r\n    printf(\"=====================\\n\");\r\n    printf(\"1:add\\n\");\r\n    printf(\"2:sub\\n\");\r\n    printf(\"3:mul\\n\");\r\n    printf(\"4:div\\n\");\r\n    printf(\"0:quit\\n\");\r\n    printf(\"=====================\\n\");\r\n}\r\n\n  <\/stdio.h><\/pre> \n 

\u7531\u4e0a\u9762\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\u6765\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u4e09\u79cd\u8c03\u7528\u65b9\u5f0f\uff1a
int (*pointer)(int ,int ) = fun_array[i];
int result = pointer(http:\/\/blog.csdn.net\/qq_29924041\/article\/details\/num1,num2);
\u6216\u8005\uff1a
int result = fun_array
i<\/a>;
\u6216\u8005\uff1a
int result =*(fun_array[i])(http:\/\/blog.csdn.net\/qq_29924041\/article\/details\/num1,num2);
\u7b2c\u4e09\u79cd\u5f62\u5f0f\u6211\u4eec\u662f\u4e0d\u7ecf\u5e38\u4f1a\u7528\u5230\u7684\uff0c<\/p> \n

\u7ed3\u679c\uff1a<\/h1> \n

1:add
2:sub
3:mul
4:div<\/p> \n

0:quit<\/h1> \n

please select a num what you want :1
please input two num you want!
10 11
the form_1_result you want to calculate is:21
the form_2_result you want to calculate is:21
the form_3_result you want to calculate is:21<\/p> \n

\u51fd\u6570\u6307\u9488\u6570\u7ec4\u7684\u8fd0\u7528\u7684\u6ce8\u610f\u70b9\uff1a<\/p> \u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u4e00\u6837\uff0c\u5e76\u4e14\u51fd\u6570\u7684\u5f62\u53c2\u4e5f\u662f\u8981\u4e00\u6837 \u901a\u5e38\u662f\u5728swith\u51fd\u6570\u4e2d\u53bb\u505a\u8fd9\u6837\u7684\u51fd\u6570\u6307\u9488\u6570\u7ec4\uff0c\u4fbf\u4e8e\u7b80\u5316\u4ee3\u7801\u3002 \n<\/dd>","orderid":"0","title":"C\u8bed\u8a00\u7684\u51fd\u6570\u6307\u9488\u6570\u7ec4","smalltitle":"","mid":"0","fname":"c\u8bed\u8a00\u7f16\u7a0b","special_id":"0","bak_id":"0","info":"0","hits":"62","pages":"1","comments":"0","posttime":"2017-01-05 08:14:48","list":"1483575288","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"http:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u8bed\u8a00<\/A> \u51fd\u6570<\/A> \u6307\u9488<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.31","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"C\u8bed\u8a00\u7684\u51fd\u6570\u6307\u9488\u6570\u7ec4","lastview":"1487737869","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}