{"id":3391,"date":"2025-03-30T21:56:30","date_gmt":"2025-03-30T13:56:30","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=3391"},"modified":"2025-03-30T21:56:30","modified_gmt":"2025-03-30T13:56:30","slug":"c-%e8%af%ad%e8%a8%80%e4%b8%ad%e7%9a%84%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/03\/30\/c-%e8%af%ad%e8%a8%80%e4%b8%ad%e7%9a%84%e5%87%bd%e6%95%b0\/","title":{"rendered":"C \u8bed\u8a00\u4e2d\u7684\u51fd\u6570"},"content":{"rendered":"\n<p>\u51fd\u6570\u662f C \u8bed\u8a00\u7684\u57fa\u672c\u7ec4\u6210\u90e8\u5206\u4e4b\u4e00\uff0c\u5b83\u5c06\u7279\u5b9a\u7684\u64cd\u4f5c\u5c01\u88c5\u5728\u4e00\u4e2a\u4ee3\u7801\u5757\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u591a\u6b21\u8c03\u7528\uff0c\u4ece\u800c\u907f\u514d\u4ee3\u7801\u7684\u91cd\u590d\u3002C \u8bed\u8a00\u652f\u6301\u51fd\u6570\u7684\u5b9a\u4e49\u3001\u58f0\u660e\u4ee5\u53ca\u8c03\u7528\uff0c\u51fd\u6570\u662f\u6a21\u5757\u5316\u7f16\u7a0b\u7684\u57fa\u7840\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. <strong>\u51fd\u6570\u7684\u5b9a\u4e49<\/strong><\/h2>\n\n\n\n<p>\u4e00\u4e2a\u51fd\u6570\u901a\u5e38\u7531\u4e09\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8fd4\u56de\u7c7b\u578b<\/strong>\uff1a\u6307\u5b9a\u51fd\u6570\u8fd4\u56de\u7684\u503c\u7c7b\u578b\uff0c\u6216\u8005\u662f <code>void<\/code>\uff0c\u8868\u793a\u51fd\u6570\u4e0d\u8fd4\u56de\u503c\u3002<\/li>\n\n\n\n<li><strong>\u51fd\u6570\u540d\u79f0<\/strong>\uff1a\u7528\u4e8e\u6807\u8bc6\u51fd\u6570\uff0c\u9075\u5faa C \u8bed\u8a00\u6807\u8bc6\u7b26\u547d\u540d\u89c4\u5219\u3002<\/li>\n\n\n\n<li><strong>\u53c2\u6570\u5217\u8868<\/strong>\uff1a\u51fd\u6570\u63a5\u6536\u7684\u8f93\u5165\uff0c\u53ef\u4ee5\u4e3a\u7a7a\u3002\u5982\u679c\u6709\u53c2\u6570\uff0c\u5b83\u4eec\u5c06\u5728\u51fd\u6570\u5185\u88ab\u4f7f\u7528\u3002<\/li>\n\n\n\n<li><strong>\u51fd\u6570\u4f53<\/strong>\uff1a\u5305\u542b\u6267\u884c\u4efb\u52a1\u7684\u4ee3\u7801\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>return_type function_name(parameter1, parameter2, ...) {\n    \/\/ \u51fd\u6570\u4f53\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u4e00\u4e2a\u7b80\u5355\u7684\u6c42\u548c\u51fd\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\n\/\/ \u51fd\u6570\u58f0\u660e\nint add(int a, int b);\n\nint main() {\n    int result = add(5, 3);  \/\/ \u8c03\u7528 add \u51fd\u6570\n    printf(\"\u7ed3\u679c\u662f\uff1a%d\\n\", result);\n    return 0;\n}\n\n\/\/ \u51fd\u6570\u5b9a\u4e49\nint add(int a, int b) {\n    return a + b;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u7ed3\u679c\u662f\uff1a8<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. <strong>\u51fd\u6570\u7684\u8fd4\u56de\u503c<\/strong><\/h2>\n\n\n\n<p>\u6bcf\u4e2a\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u8fd4\u56de\u7c7b\u578b\uff0c\u8868\u793a\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u3002\u5982\u679c\u51fd\u6570\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\uff0c\u5219\u8fd4\u56de\u7c7b\u578b\u4e3a <code>void<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void function_name() {\n    \/\/ \u8be5\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u4e00\u4e2a\u4e0d\u8fd4\u56de\u503c\u7684\u51fd\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nvoid print_hello() {\n    printf(\"Hello, World!\\n\");\n}\n\nint main() {\n    print_hello();  \/\/ \u8c03\u7528 print_hello \u51fd\u6570\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello, World!<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. <strong>\u51fd\u6570\u7684\u53c2\u6570\u4f20\u9012<\/strong><\/h2>\n\n\n\n<p>C \u8bed\u8a00\u652f\u6301\u4e24\u79cd\u4e3b\u8981\u7684\u53c2\u6570\u4f20\u9012\u65b9\u5f0f\uff1a<strong>\u503c\u4f20\u9012<\/strong>\u548c<strong>\u5f15\u7528\u4f20\u9012<\/strong>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u503c\u4f20\u9012<\/strong>\uff1a\u5c06\u5b9e\u53c2\u7684\u526f\u672c\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u5373\u4fee\u6539\u51fd\u6570\u5185\u90e8\u7684\u53c2\u6570\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>\u5f15\u7528\u4f20\u9012<\/strong>\uff08\u901a\u8fc7\u6307\u9488\u5b9e\u73b0\uff09\uff1a\u5c06\u5b9e\u53c2\u7684\u5730\u5740\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539\u539f\u59cb\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 <strong>\u503c\u4f20\u9012<\/strong><\/h3>\n\n\n\n<p>\u5728\u503c\u4f20\u9012\u4e2d\uff0c\u5b9e\u53c2\u7684\u526f\u672c\u88ab\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u51fd\u6570\u5185\u90e8\u4fee\u6539\u53c2\u6570\u7684\u503c\u4e0d\u4f1a\u5f71\u54cd\u5b9e\u53c2\u7684\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nvoid modify_value(int x) {\n    x = 20;\n    printf(\"\u4fee\u6539\u540e\u7684\u503c\uff1a%d\\n\", x);\n}\n\nint main() {\n    int a = 10;\n    modify_value(a);  \/\/ \u5b9e\u53c2 a \u7684\u526f\u672c\u88ab\u4f20\u9012\n    printf(\"\u4e3b\u51fd\u6570\u4e2d\u7684 a\uff1a%d\\n\", a);  \/\/ a \u7684\u503c\u6ca1\u6709\u6539\u53d8\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4fee\u6539\u540e\u7684\u503c\uff1a20\n\u4e3b\u51fd\u6570\u4e2d\u7684 a\uff1a10<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 <strong>\u5f15\u7528\u4f20\u9012\uff08\u901a\u8fc7\u6307\u9488\uff09<\/strong><\/h3>\n\n\n\n<p>\u901a\u8fc7\u4f20\u9012\u53d8\u91cf\u7684\u5730\u5740\uff0c\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539\u5b9e\u53c2\u7684\u503c\u3002\u8fd9\u79cd\u65b9\u5f0f\u7528\u4e8e\u9700\u8981\u4fee\u6539\u51fd\u6570\u5916\u90e8\u6570\u636e\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nvoid modify_value(int *x) {\n    *x = 20;  \/\/ \u4fee\u6539\u6307\u9488\u6240\u6307\u5411\u7684\u503c\n}\n\nint main() {\n    int a = 10;\n    modify_value(&amp;a);  \/\/ \u4f20\u9012 a \u7684\u5730\u5740\n    printf(\"\u4e3b\u51fd\u6570\u4e2d\u7684 a\uff1a%d\\n\", a);  \/\/ a \u7684\u503c\u88ab\u4fee\u6539\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4e3b\u51fd\u6570\u4e2d\u7684 a\uff1a20<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. <strong>\u9012\u5f52\u51fd\u6570<\/strong><\/h2>\n\n\n\n<p>\u9012\u5f52\u51fd\u6570\u662f\u6307\u51fd\u6570\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u76f4\u63a5\u6216\u95f4\u63a5\u8c03\u7528\u81ea\u8eab\u3002\u9012\u5f52\u51fd\u6570\u901a\u5e38\u9700\u8981\u4e00\u4e2a\u57fa\u51c6\u6761\u4ef6\uff0c\u7528\u4e8e\u505c\u6b62\u9012\u5f52\u8c03\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u8ba1\u7b97\u9636\u4e58\u7684\u9012\u5f52\u51fd\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint factorial(int n) {\n    if (n == 0)  \/\/ \u57fa\u51c6\u6761\u4ef6\n        return 1;\n    else\n        return n * factorial(n - 1);  \/\/ \u9012\u5f52\u8c03\u7528\n}\n\nint main() {\n    int result = factorial(5);  \/\/ \u8ba1\u7b97 5 \u7684\u9636\u4e58\n    printf(\"5 \u7684\u9636\u4e58\u662f\uff1a%d\\n\", result);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>5 \u7684\u9636\u4e58\u662f\uff1a120<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5. <strong>\u51fd\u6570\u7684\u58f0\u660e\u4e0e\u5b9a\u4e49<\/strong><\/h2>\n\n\n\n<p>\u5728 C \u8bed\u8a00\u4e2d\uff0c\u51fd\u6570\u7684\u58f0\u660e\u4e0e\u5b9a\u4e49\u662f\u5206\u5f00\u7684\u3002\u51fd\u6570\u58f0\u660e\u544a\u8bc9\u7f16\u8bd1\u5668\u51fd\u6570\u7684\u540d\u79f0\u3001\u8fd4\u56de\u7c7b\u578b\u548c\u53c2\u6570\u7c7b\u578b\uff0c\u51fd\u6570\u5b9a\u4e49\u5219\u662f\u51fd\u6570\u4f53\u7684\u5b9e\u73b0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u51fd\u6570\u58f0\u660e<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>return_type function_name(parameter_list);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u51fd\u6570\u5b9a\u4e49<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>return_type function_name(parameter_list) {\n    \/\/ \u51fd\u6570\u4f53\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u51fd\u6570\u58f0\u660e\u51fa\u73b0\u5728\u4e3b\u51fd\u6570\u524d\u9762\uff0c\u5219\u53ef\u4ee5\u5728\u4e3b\u51fd\u6570\u4e2d\u8c03\u7528\u8be5\u51fd\u6570\uff0c\u5426\u5219\u9700\u8981\u5728\u8c03\u7528\u524d\u58f0\u660e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u51fd\u6570\u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u5f00<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\n\/\/ \u51fd\u6570\u58f0\u660e\nint add(int, int);\n\nint main() {\n    int result = add(10, 20);  \/\/ \u8c03\u7528 add \u51fd\u6570\n    printf(\"\u7ed3\u679c\u662f\uff1a%d\\n\", result);\n    return 0;\n}\n\n\/\/ \u51fd\u6570\u5b9a\u4e49\nint add(int a, int b) {\n    return a + b;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u7ed3\u679c\u662f\uff1a30<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u51fd\u6570\u5b9a\u4e49<\/strong>\u7531\u8fd4\u56de\u7c7b\u578b\u3001\u51fd\u6570\u540d\u3001\u53c2\u6570\u5217\u8868\u548c\u51fd\u6570\u4f53\u7ec4\u6210\u3002<\/li>\n\n\n\n<li><strong>\u51fd\u6570\u8c03\u7528<\/strong>\u53ef\u4ee5\u901a\u8fc7\u503c\u4f20\u9012\u6216\u5f15\u7528\u4f20\u9012\u6765\u4f20\u9012\u53c2\u6570\u3002<\/li>\n\n\n\n<li><strong>\u9012\u5f52\u51fd\u6570<\/strong>\u53ef\u4ee5\u901a\u8fc7\u81ea\u8eab\u8c03\u7528\u89e3\u51b3\u95ee\u9898\uff0c\u4f46\u5fc5\u987b\u5b9a\u4e49\u7ec8\u6b62\u6761\u4ef6\u3002<\/li>\n\n\n\n<li><strong>\u51fd\u6570\u58f0\u660e<\/strong>\u901a\u5e38\u653e\u5728\u51fd\u6570\u5b9a\u4e49\u4e4b\u524d\uff0c\u544a\u77e5\u7f16\u8bd1\u5668\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u3001\u540d\u79f0\u53ca\u53c2\u6570\u7c7b\u578b\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u51fd\u6570\u662f\u7a0b\u5e8f\u7684\u57fa\u672c\u5355\u5143\uff0c\u901a\u8fc7\u4f7f\u7528\u51fd\u6570\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u3001\u53ef\u8bfb\u6027\u548c\u7ef4\u62a4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u51fd\u6570\u662f C \u8bed\u8a00\u7684\u57fa\u672c\u7ec4\u6210\u90e8\u5206\u4e4b\u4e00\uff0c\u5b83\u5c06\u7279\u5b9a\u7684\u64cd\u4f5c\u5c01\u88c5\u5728\u4e00\u4e2a\u4ee3\u7801\u5757\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u591a\u6b21\u8c03\u7528\uff0c\u4ece\u800c\u907f\u514d\u4ee3\u7801\u7684\u91cd\u590d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3392,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"class_list":["post-3391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=3391"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3391\/revisions"}],"predecessor-version":[{"id":3393,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3391\/revisions\/3393"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media\/3392"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=3391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=3391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=3391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}