{"id":7834,"date":"2024-07-04T14:01:01","date_gmt":"2024-07-04T06:01:01","guid":{"rendered":""},"modified":"2024-07-04T14:01:01","modified_gmt":"2024-07-04T06:01:01","slug":"\u56de\u8c03\u51fd\u6570\u548c\u51fd\u6570\u8c03\u7528_callback\u56de\u8c03\u51fd\u6570","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7834.html","title":{"rendered":"\u56de\u8c03\u51fd\u6570\u548c\u51fd\u6570\u8c03\u7528_callback\u56de\u8c03\u51fd\u6570"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u5728\u521a\u5f00\u59cb\u5b66\u4e60\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u4e0d\u5c11\u521d\u5b66\u8005\u5f04\u4e0d\u6e05\u695a\u201c\u666e\u901a\u51fd\u6570\u8c03\u7528\u201d\u548c\u201c\u56de\u8c03\u51fd\u6570\u201d\u4e4b\u95f4\u7684\u533a\u522b\uff0c\u4e0b\u9762\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u5bf9\u6bd4\u5206\u6790\u3002<\/p>\n

\u4e00\u53e5\u8bdd\u7b80\u5355\u533a\u5206<\/strong>\uff1a
\u666e\u901a\u51fd\u6570\u8c03\u7528\uff1a \u51fd\u6570\u76f4\u63a5\u88ab\u8c03\u7528
\u56de\u8c03\u51fd\u6570\uff1a\u3000\u3000 \u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u88ab\u8c03\u7528<\/p>\n

\u8fd9\u6837\u89e3\u91ca\u6216\u8bb8\u8fd8\u662f\u4e0d\u591f\u76f4\u89c2\uff0c\u6211\u4eec\u76f4\u63a5\u770b\u4f8b\u5b50\u5427\uff01<\/p>\n

\u666e\u901a\u51fd\u6570\u8c03\u7528<\/strong><\/h3>\n
#include<\/span> <stdio.h><\/span><\/span> \/\/ \u88ab\u8c03\u7528\u7684\u51fd\u65701<\/span> int<\/span> func1<\/span>(<\/span>int<\/span> value)<\/span> { \n   <\/span> printf<\/span>(<\/span>\"This is func1,value = %d\\n\"<\/span>,<\/span>value)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> \/\/ \u88ab\u8c03\u7528\u7684\u51fd\u65702<\/span> int<\/span> func2<\/span>(<\/span>int<\/span> value)<\/span> { \n   <\/span> printf<\/span>(<\/span>\"This is func2,value = %d\\n\"<\/span>,<\/span>value)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> \/\/ \u666e\u901a\u51fd\u6570\u8c03\u7528<\/span> int<\/span> handle_call_back<\/span>(<\/span>int<\/span> value1,<\/span>int<\/span> value2)<\/span> { \n   <\/span> func1<\/span>(<\/span>value1)<\/span>;<\/span> \/\/ \u51fd\u6570\u76f4\u63a5\u88ab\u8c03\u7528<\/span> func2<\/span>(<\/span>value2)<\/span>;<\/span> \/\/ \u51fd\u6570\u76f4\u63a5\u88ab\u8c03\u7528<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> int<\/span> main<\/span>(<\/span>void<\/span>)<\/span> { \n   <\/span> int<\/span> a =<\/span> 66<\/span>;<\/span> int<\/span> b =<\/span> 88<\/span>;<\/span> handle_call_back<\/span>(<\/span>a,<\/span>b)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> <\/code><\/pre>\n

\u6267\u884c\u7ed3\u679c<\/strong><\/p>\n

This is func1,<\/span>value =<\/span> 66<\/span> This is func2,<\/span>value =<\/span> 88<\/span> <\/code><\/pre>\n

\u53ef\u4ee5\u770b\u51fa\uff0c\u8fd9\u91cc\u666e\u901a\u51fd\u6570\u7684\u8c03\u7528\uff0c\u662f\u76f4\u63a5\u8c03\u7528\u51fd\u6570\u540dfunc1\u548cfunc2\u3002<\/p>\n

\u4e0d\u5e26\u53c2\u7684\u56de\u8c03\u51fd\u6570<\/h3>\n
#include<\/span> <stdio.h><\/span><\/span> \/\/ \u88ab\u8c03\u7528\u7684\u51fd\u65701<\/span> int<\/span> call_back1<\/span>(<\/span>void<\/span>)<\/span> { \n   <\/span> printf<\/span>(<\/span>\"This is call_back1\\n\"<\/span>)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> \/\/ \u88ab\u8c03\u7528\u7684\u51fd\u65702<\/span> int<\/span> call_back2<\/span>(<\/span>void<\/span>)<\/span> { \n   <\/span> printf<\/span>(<\/span>\"This is call_back2\\n\"<\/span>)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> \/\/ \u56de\u8c03\u51fd\u6570<\/span> int<\/span> handle_call_back<\/span>(<\/span>int<\/span> (<\/span>*<\/span>call_back)<\/span>(<\/span>void<\/span>)<\/span>)<\/span> { \n   <\/span> call_back<\/span>(<\/span>)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> int<\/span> main<\/span>(<\/span>void<\/span>)<\/span> { \n   <\/span> handle_call_back<\/span>(<\/span>call_back1)<\/span>;<\/span> \/\/ \u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u88ab\u8c03\u7528<\/span> handle_call_back<\/span>(<\/span>call_back2)<\/span>;<\/span> \/\/ \u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u88ab\u8c03\u7528<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> <\/code><\/pre>\n

\u6267\u884c\u7ed3\u679c<\/strong><\/p>\n

This is call_back1 This is call_back2 <\/code><\/pre>\n

\u53ef\u4ee5\u770b\u51fa\uff0ccall_back\u7cfb\u5217\u51fd\u6570\u662f\u4f5c\u4e3ahandle_call_back\u7684\u53c2\u6570\u88ab\u8c03\u7528\u7684\u3002\u4e0a\u9762\u662f\u4e0d\u5e26\u53c2\u6570\u7684\u56de\u8c03\u51fd\u6570\uff0c\u90a3\u5e26\u53c2\u7684\u56de\u8c03\u51fd\u6570\u5462\uff1f<\/p>\n

\u5e26\u53c2\u6570\u7684\u56de\u8c03\u51fd\u6570<\/h3>\n
#include<\/span> <stdio.h><\/span><\/span> \/\/ \u88ab\u8c03\u7528\u7684\u51fd\u65701<\/span> int<\/span> call_back1<\/span>(<\/span>int<\/span> value1)<\/span> { \n   <\/span> printf<\/span>(<\/span>\"This is call_back1,value = %d\\n\"<\/span>,<\/span>value1)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> \/\/ \u88ab\u8c03\u7528\u7684\u51fd\u65702<\/span> int<\/span> call_back2<\/span>(<\/span>int<\/span> value2)<\/span> { \n   <\/span> printf<\/span>(<\/span>\"This is call_back2,value = %d\\n\"<\/span>,<\/span>value2)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> \/\/ \u56de\u8c03\u51fd\u6570<\/span> int<\/span> handle_call_back<\/span>(<\/span>int<\/span> value,<\/span>int<\/span> (<\/span>*<\/span>call_back)<\/span>(<\/span>int<\/span>)<\/span>)<\/span> { \n   <\/span> call_back<\/span>(<\/span>value)<\/span>;<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> int<\/span> main<\/span>(<\/span>void<\/span>)<\/span> { \n   <\/span> int<\/span> a =<\/span> 10<\/span>;<\/span> int<\/span> b =<\/span> 20<\/span>;<\/span> handle_call_back<\/span>(<\/span>a,<\/span>call_back1)<\/span>;<\/span> \/\/ \u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u88ab\u8c03\u7528<\/span> handle_call_back<\/span>(<\/span>b,<\/span>call_back2)<\/span>;<\/span> \/\/ \u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u88ab\u8c03\u7528<\/span> return<\/span> 0<\/span>;<\/span> }<\/span> <\/code><\/pre>\n

\u6267\u884c\u7ed3\u679c<\/strong><\/p>\n

This is call_back1,<\/span>value =<\/span> 10<\/span> This is call_back2,<\/span>value =<\/span> 20<\/span> <\/code><\/pre>\n

\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa\uff0chandle_call_back\u4e2d\u7684\u53c2\u6570value\uff0c\u53ef\u4ee5\u4f20\u7ed9int (*call_back)(int)\uff0c\u5b9e\u73b0\u4e86\u5e26\u53c2\u56de\u8c03\u51fd\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u56de\u8c03\u51fd\u6570\u548c\u51fd\u6570\u8c03\u7528_callback\u56de\u8c03\u51fd\u6570\u5728\u521a\u5f00\u59cb\u5b66\u4e60\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u4e0d\u5c11\u521d\u5b66\u8005\u5f04\u4e0d\u6e05\u695a\u201c\u666e\u901a\u51fd\u6570\u8c03\u7528\u201d\u548c\u201c\u56de\u8c03\u51fd\u6570\u201d\u4e4b\u95f4\u7684\u533a\u522b\uff0c\u4e0b...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7834"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7834"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7834\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}