{"id":74475,"date":"2024-02-27T11:01:00","date_gmt":"2024-02-27T03:01:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=74475"},"modified":"2024-02-27T11:01:15","modified_gmt":"2024-02-27T03:01:15","slug":"c-%e8%af%ad%e8%a8%80%e4%b8%ad%ef%bc%8c%e3%80%8c-%e3%80%8d%e4%b8%8e%e3%80%8c-%e3%80%8d%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/74475.html","title":{"rendered":"C \u8bed\u8a00\u4e2d\uff0c\u300c.\u300d\u4e0e\u300c->\u300d\u6709\u4ec0\u4e48\u533a\u522b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-74476\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/02\/generated_00-51.png?x-oss-process=image\/auto-orient,1\/format,webp\" width=\"600\" height=\"342\" \/>\u300d\u6709\u4ec0\u4e48\u533a\u522b&#8221; \/><\/p>\n<p>### C \u8bed\u8a00\u4e2d\uff0c\u300c.\u300d\u4e0e\u300c->\u300d\u6709\u4ec0\u4e48\u533a\u522b<\/p>\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c<strong>\u300c.\u300d\u548c\u300c->\u300d\u90fd\u7528\u4e8e\u8bbf\u95ee\u7ed3\u6784\u4f53\u6216\u8054\u5408\u4f53\u4e2d\u7684\u6210\u5458<\/strong>\uff0c\u4f46\u5b83\u4eec\u7684\u4f7f\u7528\u573a\u666f\u548c\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\u3002<strong>\u300c.\u300d\u8fd0\u7b97\u7b26\u7528\u4e8e\u901a\u8fc7\u7ed3\u6784\u4f53\u53d8\u91cf\u76f4\u63a5\u8bbf\u95ee\u5176\u6210\u5458<\/strong>\u3001<strong>\u800c\u300c->\u300d\u8fd0\u7b97\u7b26\u7528\u4e8e\u901a\u8fc7\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488\u6765\u8bbf\u95ee\u5176\u6210\u5458<\/strong>\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5f53\u4f60\u62e5\u6709\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf\u65f6\uff0c\u4f60\u4f1a\u4f7f\u7528\u300c.\u300d\u8fd0\u7b97\u7b26\u6765\u8bbf\u95ee\u5176\u5185\u90e8\u7684\u6210\u5458\uff1b\u800c\u5f53\u4f60\u6709\u4e00\u4e2a\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488\u65f6\uff0c\u4f60\u9700\u8981\u4f7f\u7528\u300c->\u300d\u8fd0\u7b97\u7b26\u6765\u8bbf\u95ee\u6307\u9488\u6240\u6307\u5411\u7684\u7ed3\u6784\u4f53\u7684\u6210\u5458\u3002<\/p>\n<p>#### \u4e00\u3001\u57fa\u672c\u6982\u5ff5\u4e0e\u4f7f\u7528\u573a\u666f<\/p>\n<p><strong>\u7ed3\u6784\u4f53\u53d8\u91cf\u7684\u6210\u5458\u8bbf\u95ee<\/strong><\/p>\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u7ed3\u6784\u4f53\uff08struct\uff09\u662f\u4e00\u79cd\u5141\u8bb8\u5c06\u591a\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u9879\u7ec4\u7ec7\u6210\u4e00\u4e2a\u5355\u4e00\u5b9e\u4f53\u7684\u590d\u5408\u6570\u636e\u7c7b\u578b\u3002\u5047\u8bbe\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ed3\u6784\u4f53\u7c7b\u578b`struct Person`\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a\u8be5\u7c7b\u578b\u7684\u53d8\u91cf`p`\u3002\u8981\u8bbf\u95ee`p`\u4e2d\u7684\u67d0\u4e2a\u6210\u5458\uff0c\u4f8b\u5982`name`\uff0c\u6211\u4eec\u4f7f\u7528\u70b9\u8fd0\u7b97\u7b26\uff1a`p.name`\u3002<\/p>\n<p>&#8220;`c<\/p>\n<p>struct Person {<\/p>\n<p>    char name[50];<\/p>\n<p>    int age;<\/p>\n<p>};<\/p>\n<p>struct Person p;<\/p>\n<p>strcpy(p.name, &#8220;Alice&#8221;);<\/p>\n<p>p.age = 30;<\/p>\n<p>printf(&#8220;Name: %s, Age: %d\\n&#8221;, p.name, p.age);<\/p>\n<p>&#8220;`<\/p>\n<p><strong>\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488\u8bbf\u95ee\u6210\u5458<\/strong><\/p>\n<p>\u5f53\u6211\u4eec\u6709\u4e00\u4e2a\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488\u65f6\uff0c\u6bd4\u5982`struct Person *ptr`\uff0c\u6b64\u65f6\u8981\u8bbf\u95ee\u6307\u9488\u6240\u6307\u5411\u7684\u7ed3\u6784\u4f53\u7684\u6210\u5458\uff0c\u6211\u4eec\u4f7f\u7528\u7bad\u5934\u8fd0\u7b97\u7b26`->`\u3002\u8fd9\u6837\uff0c`ptr->name`\u548c`ptr->age`\u5141\u8bb8\u6211\u4eec\u8bbf\u95ee\u7ed3\u6784\u4f53\u4e2d\u7684`name`\u548c`age`\u6210\u5458\u3002<\/p>\n<p>&#8220;`c<\/p>\n<p>struct Person *ptr = &p;<\/p>\n<p>printf(&#8220;Name: %s, Age: %d\\n&#8221;, ptr->name, ptr->age);<\/p>\n<p>&#8220;`<\/p>\n<p>#### \u4e8c\u3001\u8bed\u6cd5\u5dee\u5f02\u4e0e\u5b9e\u73b0\u539f\u7406<\/p>\n<p><strong>\u8bed\u6cd5\u5dee\u5f02<\/strong><\/p>\n<p>\u4ece\u8bed\u6cd5\u5c42\u9762\u4e0a\u770b\uff0c\u300c.\u300d\u548c\u300c->\u300d\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u5b83\u4eec\u5404\u81ea\u64cd\u4f5c\u7684\u5bf9\u8c61\u3002\u70b9\u8fd0\u7b97\u7b26\u300c.\u300d\u64cd\u4f5c\u7684\u662f\u5b9e\u4f53\uff08\u53d8\u91cf\u672c\u8eab\uff09\uff0c\u800c\u7bad\u5934\u8fd0\u7b97\u7b26\u300c->\u300d\u64cd\u4f5c\u7684\u662f\u6307\u9488\u3002\u8fd9\u79cd\u5dee\u5f02\u76f4\u63a5\u5bfc\u81f4\u4e86\u5b83\u4eec\u5728\u4f7f\u7528\u65f6\u7684\u4e0d\u540c\u70b9\uff1a\u4f7f\u7528\u300c.\u300d\u65f6\uff0c\u64cd\u4f5c\u7684\u76f4\u63a5\u662f\u53d8\u91cf\uff1b\u4f7f\u7528\u300c->\u300d\u65f6\uff0c\u64cd\u4f5c\u7684\u662f\u53d8\u91cf\u5730\u5740\u6240\u6307\u5411\u7684\u503c\u3002<\/p>\n<p><strong>\u5b9e\u73b0\u539f\u7406<\/strong><\/p>\n<p>\u4ece\u5b9e\u73b0\u539f\u7406\u4e0a\u8bb2\uff0c\u300c->\u300d\u8fd0\u7b97\u7b26\u53ef\u4ee5\u89c6\u4e3a\u5bf9\u300c*\u300d\uff08\u89e3\u5f15\u7528\u8fd0\u7b97\u7b26\uff09\u548c\u300c.\u300d\u8fd0\u7b97\u7b26\u7684\u7ed3\u5408\u4f7f\u7528\u7684\u7b80\u5316\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c`ptr->member`\u5728\u5e95\u5c42\u7b49\u4ef7\u4e8e`(*ptr).member`\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5f53\u4f7f\u7528\u300c->\u300d\u8fd0\u7b97\u7b26\u65f6\uff0c\u9996\u5148\u4f1a\u5bf9\u6307\u9488\u8fdb\u884c\u89e3\u5f15\u7528\uff08\u5373\u83b7\u53d6\u6307\u9488\u6240\u6307\u5411\u7684\u7ed3\u6784\u4f53\u53d8\u91cf\uff09\uff0c\u7136\u540e\u8bbf\u95ee\u8be5\u7ed3\u6784\u4f53\u53d8\u91cf\u7684\u6210\u5458\u3002<\/p>\n<p>#### \u4e09\u3001\u4f7f\u7528\u573a\u666f\u6bd4\u8f83<\/p>\n<p><strong>\u4f18\u52bf\u53ca\u9002\u7528\u60c5\u51b5<\/strong><\/p>\n<p>\u4f7f\u7528\u300c.\u300d\u8fd0\u7b97\u7b26\u7684\u573a\u666f\u901a\u5e38\u8f83\u4e3a\u76f4\u63a5\u7b80\u5355\uff0c\u5f53\u4f60\u76f4\u63a5\u64cd\u4f5c\u7ed3\u6784\u4f53\u53d8\u91cf\u65f6\uff0c\u8fd9\u662f\u6700\u76f4\u89c2\u7684\u9009\u62e9\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u300c->\u300d\u8fd0\u7b97\u7b26\u9002\u7528\u4e8e\u5904\u7406\u52a8\u6001\u5206\u914d\u7684\u7ed3\u6784\u4f53\uff0c\u6216\u8005\u5f53\u7ed3\u6784\u4f53\u9700\u8981\u5728\u591a\u4e2a\u51fd\u6570\u95f4\u5171\u4eab\u65f6\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u6307\u9488\u80fd\u591f\u63d0\u4f9b\u66f4\u5927\u7684\u7075\u6d3b\u6027\u548c\u6548\u7387\u3002<\/p>\n<p><strong>\u6027\u80fd\u8003\u8651<\/strong><\/p>\n<p>\u4ece\u6027\u80fd\u89d2\u5ea6\u6765\u770b\uff0c\u4e24\u79cd\u8fd0\u7b97\u7b26\u7684\u5dee\u5f02\u901a\u5e38\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\u3002\u4f46\u662f\uff0c\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u8005\u5728\u6027\u80fd\u654f\u611f\u7684\u5e94\u7528\u4e2d\uff0c\u5408\u7406\u9009\u62e9\u4f7f\u7528\u76f4\u63a5\u8bbf\u95ee\u8fd8\u662f\u6307\u9488\u8bbf\u95ee\u53ef\u4ee5\u5e26\u6765\u5fae\u5c0f\u7684\u6027\u80fd\u4f18\u52bf\u3002<\/p>\n<p>#### \u56db\u3001\u5b9e\u9645\u5e94\u7528\u793a\u4f8b<\/p>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u300c.\u300d\u548c\u300c->\u300d\u7684\u9009\u62e9\u53d6\u51b3\u4e8e\u5177\u4f53\u60c5\u51b5\u3002\u4f8b\u5982\uff0c\u5728\u5b9a\u4e49\u6570\u636e\u7ed3\u6784\u5e76\u9700\u8981\u9891\u7e41\u8bbf\u95ee\u6210\u5458\u65f6\uff0c\u5408\u7406\u4f7f\u7528\u8fd9\u4e24\u79cd\u8fd0\u7b97\u7b26\u80fd\u591f\u4f7f\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u548c\u9ad8\u6548\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u8fd9\u4e24\u79cd\u8fd0\u7b97\u7b26\u6765\u64cd\u4f5c\u7ed3\u6784\u4f53\u6210\u5458\u3002<\/p>\n<p>&#8220;`c<\/p>\n<p>#include <stdio.h><\/p>\n<p>#include <string.h><\/p>\n<p>struct Person {<\/p>\n<p>    char name[50];<\/p>\n<p>    int age;<\/p>\n<p>};<\/p>\n<p>void printPersonInfo(struct Person p) {<\/p>\n<p>    printf(&#8220;Name: %s, Age: %d\\n&#8221;, p.name, p.age);<\/p>\n<p>}<\/p>\n<p>void updatePersonAge(struct Person *p, int newAge) {<\/p>\n<p>    p->age = newAge;<\/p>\n<p>}<\/p>\n<p>int m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n() {<\/p>\n<p>    struct Person person;<\/p>\n<p>    strcpy(person.name, &#8220;Bob&#8221;);<\/p>\n<p>    person.age = 25;<\/p>\n<p>    printPersonInfo(person); \/\/ \u4f7f\u7528.\u8bbf\u95ee<\/p>\n<p>    updatePersonAge(&#038;person, 30); \/\/ \u4f7f\u7528->\u8bbf\u95ee<\/p>\n<p>    printPersonInfo(person);<\/p>\n<p>    return 0;<\/p>\n<p>}<\/p>\n<p>&#8220;`<\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c`printPersonInfo`\u51fd\u6570\u76f4\u63a5\u64cd\u4f5c\u7ed3\u6784\u4f53\u53d8\u91cf\u6765\u8bbf\u95ee\u6210\u5458\uff0c\u800c`updatePersonAge`\u51fd\u6570\u5219\u901a\u8fc7\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488\u6765\u4fee\u6539\u6210\u5458\u7684\u503c\u3002<\/p>\n<p>#### \u7ed3\u8bba<\/p>\n<p>\u7406\u89e3\u5e76\u6b63\u786e\u4f7f\u7528\u300c.\u300d\u548c\u300c->\u300d\u5bf9\u4e8e\u9ad8\u6548\u5730\u4f7f\u7528C\u8bed\u8a00\u8fdb\u884c\u7ed3\u6784\u4f53\u76f8\u5173\u7f16\u7a0b\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u9009\u62e9\u54ea\u4e00\u79cd\u8fd0\u7b97\u7b26\u53d6\u51b3\u4e8e\u4f60\u662f\u76f4\u63a5\u64cd\u4f5c\u7ed3\u6784\u4f53\u5b9e\u4f53\u8fd8\u662f\u901a\u8fc7\u6307\u9488\u64cd\u4f5c\uff0c\u638c\u63e1\u5b83\u4eec\u7684\u4f7f\u7528\u80fd\u591f\u8ba9\u4f60\u66f4\u52a0\u7075\u6d3b\u5730\u5904\u7406\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u4ec0\u4e48\u662fC\u8bed\u8a00\u4e2d\u7684\u201c.\u201d\u548c\u201c->\u201d\u8fd0\u7b97\u7b26\uff1f<\/strong><\/p>\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u201c.\u201d\u548c\u201c->\u201d\u8fd9\u4e24\u4e2a\u8fd0\u7b97\u7b26\u90fd\u7528\u6765\u8bbf\u95ee\u7ed3\u6784\u4f53\u7c7b\u578b\u7684\u6210\u5458\u3002\u5176\u4e2d\uff0c\u201c.\u201d\u7528\u4e8e\u76f4\u63a5\u8bbf\u95ee\u7ed3\u6784\u4f53\u53d8\u91cf\u7684\u6210\u5458\uff0c\u800c\u201c->\u201d\u7528\u4e8e\u8bbf\u95ee\u6307\u5411\u7ed3\u6784\u4f53\u53d8\u91cf\u7684\u6307\u9488\u6240\u6307\u5411\u7684\u6210\u5458\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u201c.\u201d\u548c\u201c->\u201d\u8fd0\u7b97\u7b26\uff1f<\/strong><\/p>\n<p>\u5f53\u6211\u4eec\u6709\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c.\u201d\u8fd0\u7b97\u7b26\u76f4\u63a5\u8bbf\u95ee\u5176\u6210\u5458\uff0c\u4f8b\u5982\uff1a`struct Person p; p.age = 20;`\u3002<\/p>\n<p>\u800c\u5f53\u6211\u4eec\u6709\u4e00\u4e2a\u6307\u5411\u7ed3\u6784\u4f53\u53d8\u91cf\u7684\u6307\u9488\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u201c->\u201d\u8fd0\u7b97\u7b26\u6765\u8bbf\u95ee\u5176\u6210\u5458\uff0c\u4f8b\u5982\uff1a`struct Person *ptr = &p; ptr->age = 25;`\u3002<\/p>\n<p><strong>\u5728C\u8bed\u8a00\u4e2d\uff0c\u201c.\u201d\u548c\u201c->\u201d\u6709\u4ec0\u4e48\u4f7f\u7528\u9650\u5236\uff1f<\/strong><\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u4f7f\u7528\u201c->\u201d\u8fd0\u7b97\u7b26\u65f6\uff0c\u5de6\u8fb9\u5fc5\u987b\u662f\u4e00\u4e2a\u6307\u5411\u7ed3\u6784\u4f53\u7684\u6307\u9488\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u7f16\u8bd1\u9519\u8bef\u3002\u53e6\u5916\uff0c\u65e0\u8bba\u662f\u4f7f\u7528\u201c.\u201d\u8fd8\u662f\u201c->\u201d\uff0c\u90fd\u53ea\u80fd\u8bbf\u95ee\u7ed3\u6784\u4f53\u81ea\u8eab\u7684\u6210\u5458\uff0c\u65e0\u6cd5\u8bbf\u95ee\u5176\u5185\u90e8\u5d4c\u5957\u7684\u7ed3\u6784\u4f53\u7684\u6210\u5458\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u300d\u6709\u4ec0\u4e48\u533a\u522b&#8221; \/> ### C \u8bed\u8a00\u4e2d\uff0c\u300c.\u300d\u4e0e\u300c->\u300d\u6709\u4ec0\u4e48\u533a\u522b \u5728C\u8bed\u8a00\u4e2d\uff0c\u300c.\u300d\u548c\u300c->\u300d [&hellip;]","protected":false},"author":1,"featured_media":74478,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/74475"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=74475"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/74475\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/74478"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=74475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=74475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=74475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}