{"id":1494,"date":"2022-01-08T16:20:04","date_gmt":"2022-01-08T08:20:04","guid":{"rendered":"http:\/\/139.9.1.231\/?p=1494"},"modified":"2022-01-08T16:20:05","modified_gmt":"2022-01-08T08:20:05","slug":"function","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/08\/function\/","title":{"rendered":"C++\u51fd\u6570\uff08\u91cd\u70b9\uff09"},"content":{"rendered":"\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large\"><img src=\"https:\/\/images.unsplash.com\/photo-1580490460709-9e7c88a0a174?ixlib=rb-1.2.1&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=1470&amp;q=80\" alt=\"\"\/><\/figure><\/div>\n\n\n\n<ul><li>\u51fd\u6570\u548c\u6570\u7ec4<\/li><li>\u51fd\u6570\u548c\u7ed3\u6784<\/li><li>\u51fd\u6570\u548c\u6307\u9488<\/li><li>\u51fd\u6570\u548cstring<\/li><li>\u51fd\u6570\u9012\u5f52<\/li><\/ul>\n\n\n\n<p class=\"has-light-gray-background-color has-background\">\u51fd\u6570\u5b9a\u4e49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typename functionnname(parameterlist){\n     statements;\n     return value;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-light-gray-background-color has-background\">\u51fd\u6570\u539f\u578b\uff1a\u5982\u679c\u51fd\u6570\u5b9a\u4e49\u5728\u51fd\u6570\u8c03\u7528\u4e4b\u540e\uff0c\u5fc5\u987b\u5728\u51fd\u6570\u8c03\u7528\u524d\u8fdb\u884c\u51fd\u6570\u539f\u578b\u58f0\u660e\uff0c\u51fd\u6570\u539f\u578b\u63cf\u8ff0\u4e86\u51fd\u6570\u5230\u7f16\u8bd1\u5668\u7684\u63a5\u53e3\uff0c\u5c06\u51fd\u6570\u8fd4\u56de\u503c\u7c7b\u578b\u3001\u53c2\u6570\u7c7b\u578b\u548c\u6570\u91cf\u544a\u8bc9\u7f16\u8bd1\u5668\u3002  \u51fd\u6570\u539f\u578b\u662f\u4e00\u6761\u8bed\u53e5\uff0c\u5c31\u662f\u51fd\u6570\u5b9a\u4e49\u4e2d\u7684\u51fd\u6570\u5934\uff0c\u6b64\u5916\uff0c\u5728\u539f\u578b\u7684\u53c2\u6570\u4e2d\u4e0d\u8981\u6c42\u63d0\u4f9b\u53d8\u91cf\u540d\uff0c\u6709\u7c7b\u578b\u5217\u8868\u5c31\u8db3\u591f\u4e86\u3002<\/p>\n\n\n\n<p class=\"has-light-gray-background-color has-background\">\u51fd\u6570\u53c2\u6570\u548c\u6309\u503c\u4f20\u9012\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"778\" height=\"442\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-144.png\" alt=\"\" class=\"wp-image-1614\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-144.png 778w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-144-300x170.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-144-768x436.png 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/figure>\n\n\n\n<h2><strong>\u51fd\u6570\u548c\u6570\u7ec4\uff1a<\/strong><\/h2>\n\n\n\n<p>1\u3001\u8f93\u5165\u4e3a\u6570\u7ec4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5b9a\u4e49\uff1a\nint sum_array (int array&#91;],int n)\n\u5b9e\u9645\u60c5\u51b5\u662farray\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5728\u51fd\u6570\u5185\u90e8\uff0carray\u53ef\u4ee5\u770b\u6210\u662f\u6570\u7ec4\n\u8c03\u7528\uff1a\nsum_array(cooke,4) \u5176\u4e2dcooke\u662f\u6570\u7ec4\u540d<\/code><\/pre>\n\n\n\n<p>2\u3001\u4f7f\u7528\u6307\u9488\u5904\u7406\u6570\u7ec4:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6570\u7ec4\u540d==\u6307\u9488\n\n\n\u5b9a\u4e49\uff1a\nint sum_array (int* array,int n)\n\u8c03\u7528\uff1a\nsum_array(cooke,4) \u5176\u4e2dcooke\u662f\u6570\u7ec4\u540d<\/code><\/pre>\n\n\n\n<p>3\u3001\u4f7f\u7528 \u8f93\u5165\u4e3a\u6570\u7ec4\u533a\u95f4\u7684\u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> int sum_array (const int* start,const int* end ) \n\u8c03\u7528\uff1a\n\nsum_array(cooke,cooke+3) \u5176\u4e2dcooke\u662f\u6570\u7ec4\u540d<\/code><\/pre>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u6307\u9488\u548cconst\uff1a<\/p>\n\n\n\n<p>\u5c06const\u7528\u4e8e\u6307\u9488\u6709\u5f88\u5fae\u5999\u7684\u5730\u65b9\uff0c\u7b2c\u4e00\u79cd\u65b9\u6cd5\u662f\u8ba9\u6307\u9488\u6307\u5411\u4e00\u4e2a\u5e38\u91cf\u5bf9\u8c61\uff0c\u8fd9\u6837\u53ef\u4ee5\u9632\u6b62\u8be5\u6307\u9488\u6765\u4fee\u6539\u6240\u6307\u5411\u7684\u503c\uff0c\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u662f\u5c06\u6307\u9488\u672c\u8eab\u58f0\u660e\u4e3a\u5e38\u91cf\uff0c\u9632\u6b62\u6539\u53d8\u6307\u9488\u6307\u5411\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"158\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-145-1024x158.png\" alt=\"\" class=\"wp-image-1617\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-145-1024x158.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-145-300x46.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-145-768x118.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-145.png 1241w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u4f46pt\u7684\u58f0\u660e\u5e76\u4e0d\u610f\u5473\u7740\u5b83\u6307\u5411\u7684\u503c\u5b9e\u9645\u4e0a\u5c31\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u800c\u53ea\u610f\u5473\u7740\u961f\u533bpt\u6765\u8bf4\uff0c\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539age\u6765 \u6539\u53d8age\u503c\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1ac++\u7981\u6b62\u5c06const\u5730\u5740\u4ed8\u7ed9\u975econst\u7684\u6307\u9488\uff0c\u9664\u975e\u4f7f\u7528\u5f3a\u5236\u51c6\u6362\u3002<\/p>\n\n\n\n<p class=\"has-light-gray-background-color has-background\">\u51fd\u6570\u548c\u4e8c\u7ef4\u6570\u7ec4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5b9a\u4e49\u51fd\u6570\uff1a \u6ce8\u610f\u8fd9\u4e2a&#91;4]\u4e2d\u7684\u6570\u5b57\u5fc5\u4e0d\u53ef\u5c11\nint sum_array (int array&#91;]&#91;4],int n)\n\u8c03\u7528:\n\nsum_array (cooke,4)\n\nor\n\u5b9a\u4e49\uff1aarray\u662f\u4e00\u4e2a\u75314\u4e2a\u6307\u5411int\u7684\u6307\u9488\u7ec4\u6210\u7684\u6570\u7ec4\nint sum_array (int (*array)&#91;4],int n)\n<\/code><\/pre>\n\n\n\n<h2><strong>\u51fd\u6570\u548cc\u98ce\u683c\u5b57\u7b26\u4e32<\/strong><\/h2>\n\n\n\n<p>\u8868\u793a\u5b57\u7b26\u4e32\u65b9\u6cd5\u6709\u4e09\u79cd\uff1a<\/p>\n\n\n\n<p>char\u6570\u7ec4 \u3001\u7528\u62ec\u53f7\u5f15\u8d77\u7684\u5b57\u7b26\u4e32\u5e38\u91cf\u3001\u88ab\u8bbe\u7f6e\u4e3a\u5b57\u7b26\u4e32\u7684\u5730\u5740\u7684char\u6307\u9488\u3002<\/p>\n\n\n\n<p>\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570\u6765\u4f20\u9012\uff0c\u5b9e\u9645\u4f20\u9012\u7684\u662f\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684\u5730\u5740\uff0c\u56e0\u6b64\uff0c\u9700\u8981\u5728\u51fd\u6570\u4e2d\u5c06\u8868\u793a\u5b57\u7b26\u4e32\u7684\u5f62\u53c2\u58f0\u660e\u4e3achar * \u7c7b\u578b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int \u51fd\u6570\u540d(const char * str,char ch)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"789\" height=\"544\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-146.png\" alt=\"\" class=\"wp-image-1626\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-146.png 789w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-146-300x207.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-146-768x530.png 768w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/figure>\n\n\n\n<p class=\"has-light-gray-background-color has-background\">\u51fd\u6570\u8fd4\u56dec\u98ce\u683c\u5b57\u7b26\u4e32\u7684\u51fd\u6570<\/p>\n\n\n\n<p>\u5728\u51fd\u6570\u5185\u90e8 \u58f0\u660e\u4e00\u4e2a\u5b57\u7b26\u4e32\u6307\u9488 \uff1a char * x = char [n+1],\u7136\u540ereturn x<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u51fd\u6570\u548c\u7ed3\u6784\uff1a<\/p>\n\n\n\n<p>\u5b9a\u4e49\u7ed3\u6784\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct tracal{\n    int x\uff1b\n    char y\uff1b\n}\n\u58f0\u660e\u51fd\u6570\u539f\u578b\uff1a\ntracal sum(tracal x)\n\u4e5f\u53ef\u4ee5\u4f20\u9012\u7ed3\u6784\u7684\u5730\u5740\uff1a\ntracal sum(tracal *x)\n\n<\/code><\/pre>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u51fd\u6570\u548cstring \u5bf9\u8c61 array\u5bf9\u8c61<\/p>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u51fd\u6570\u9012\u5f52\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"258\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-147-1024x258.png\" alt=\"\" class=\"wp-image-1632\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-147-1024x258.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-147-300x76.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-147-768x194.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-147.png 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u51fd\u6570\u6307\u9488\uff1a<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u4e5f\u6709\u5730\u5740\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u9488\u83b7\u53d6\u5230\u51fd\u6570\u7684\u5730\u5740\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570<\/strong><\/p>\n\n\n\n<ol><li><strong>\u83b7\u53d6\u51fd\u6570\u7684\u5730\u5740<\/strong>\uff1a\u83b7\u53d6 \u51fd\u6570\u5730\u5740\u5f88\u7b80\u5355 \uff0c\u53ea\u8981 \u4f7f\u7528\u51fd\u6570\u540d\uff08\u4e0d\u52a0\u53c2\u6570\u5373\u53ef\uff09\uff0c\u4f8b\u5982think()\u662f\u4e00\u4e2a\u51fd\u6570\u540d\uff0c\u90a3\u4e48\u51fd\u6570\u5730\u5740\u5c31\u662fthink\u3002<\/li><\/ol>\n\n\n\n<p class=\"has-bright-blue-background-color has-background\">\u5982\u679c\u8981\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u8fdb\u884c\u4f20\u9012\uff0c\u5fc5\u987b\u662f\u4f20\u9012\u51fd\u6570\u540d\uff1b<\/p>\n\n\n\n<ol start=\"2\"><li>\u58f0\u660e\u51fd\u6570\u6307\u9488\uff1a<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5bf9\u4e8e\u51fd\u6570\uff1adouble pam(int)\n\u58f0\u660e\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff1a\ndouble (*pf) (int)\n\u548c\u51fd\u6570\u58f0\u660e\u7c7b\u4f3c\uff0c\u4e0d\u8fc7\u662f\u5c06\u51fd\u6570\u540d\u6539\u4e3a\u6307\u9488\uff08\u52a0\u62ec\u53f7\uff09\uff0c\n\n<strong><em>(*pf) (int)\u610f\u5473\u7740\u662f\u4e00\u4e2a \u6307\u5411\u51fd\u6570\u7684\u6307\u9488<\/em><\/strong>\n\n<\/code><\/pre>\n\n\n\n<ol start=\"3\"><li>\u4f7f\u7528\u51fd\u6570\u6307\u9488\u8c03\u7528\u51fd\u6570<\/li><\/ol>\n\n\n\n<p> double (*pf) (int) \u5b9a\u4e49\u4e4b\u540e<\/p>\n\n\n\n<p>\u4ee4\uff1a pf = pam\uff08\u51fd\u6570\u540d\uff09<\/p>\n\n\n\n<p>\u8c03\u7528\uff1ax=(*pf)(5) <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"969\" height=\"250\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-148.png\" alt=\"\" class=\"wp-image-1635\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-148.png 969w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-148-300x77.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-148-768x198.png 768w\" sizes=\"(max-width: 969px) 100vw, 969px\" \/><\/figure>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">typeof  \u522b\u540d<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"806\" height=\"35\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-149.png\" alt=\"\" class=\"wp-image-1636\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-149.png 806w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-149-300x13.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-149-768x33.png 768w\" sizes=\"(max-width: 806px) 100vw, 806px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u51fd\u6570\u548c\u6570\u7ec4 \u51fd\u6570\u548c\u7ed3\u6784 \u51fd\u6570\u548c\u6307\u9488 \u51fd\u6570\u548cstring \u51fd\u6570\u9012\u5f52 \u51fd\u6570\u5b9a\u4e49\uff1a \u51fd\u6570\u539f\u578b\uff1a\u5982\u679c\u51fd\u6570\u5b9a\u4e49\u5728\u51fd\u6570\u8c03\u7528 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/08\/function\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">C++\u51fd\u6570\uff08\u91cd\u70b9\uff09<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1494"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=1494"}],"version-history":[{"count":20,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1494\/revisions"}],"predecessor-version":[{"id":1637,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1494\/revisions\/1637"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=1494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=1494"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=1494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}