﻿{"id":44,"date":"2026-02-13T14:00:49","date_gmt":"2026-02-13T06:00:49","guid":{"rendered":"https:\/\/sncn.eu.org\/blog\/?p=44"},"modified":"2026-02-13T14:12:30","modified_gmt":"2026-02-13T06:12:30","slug":"44","status":"publish","type":"post","link":"https:\/\/sncn.eu.org\/blog\/archives\/44","title":{"rendered":"\u7ed3\u6784\u4f53\u5173\u952e\u5b57struct\u548c\u521b\u5efa\u65b0\u7684\u7c7b\u578b\u540d\u5173\u952e\u5b57typedef\u7528\u6cd5"},"content":{"rendered":"\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u6709\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u58f0\u660e\u548c\u4f7f\u7528\u7ed3\u6784\u4f53\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5982\u679c\u4f7f\u7528&nbsp;<code>struct student<\/code>&nbsp;\u4f5c\u4e3a\u7c7b\u578b\u540d\uff0c\u90a3\u4e48\u6bcf\u6b21\u4f7f\u7528\u65f6\u90fd\u9700\u8981\u5e26\u4e0a&nbsp;<code>struct<\/code>&nbsp;\u5173\u952e\u5b57\uff1a<\/li>\n<\/ol>\n\n\n\n<p>    <code>struct student *b; \/\/ \u5fc5\u987b\u4f7f\u7528 struct student<\/code><\/p>\n\n\n\n<p>  2.\u5982\u679c\u60f3\u7701\u7565\u00a0<code>struct<\/code>\u00a0\u5173\u952e\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u00a0<code>typedef<\/code>\u00a0\u6765\u521b\u5efa\u65b0\u7684\u7c7b\u578b\u540d\uff1a<\/p>\n\n\n\n<p><code>typedef struct student {<br>long sno;<br>char name[10];<br>float score[3];<br>} Student; \/\/ \u521b\u5efa\u65b0\u7684\u7c7b\u578b\u540d Student\/\/ \u73b0\u5728\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 Student<br>Student *b; \/\/ \u4e0d\u9700\u8981\u5199 struct<\/code><\/p>\n\n\n\n<p>\u539f\u59cb\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\nstruct student {\n    long sno;\n    char name&#91;10];\n    float score&#91;3];\n};\n\nvoid fun(struct student *b) {\n    b-&gt;sno = 10004;           \/\/ \u4fee\u6539\u5b66\u53f7,\u6216\uff1a(*b).sno = 10004;\n    strcpy(b-&gt;name, \"LiJie\"); \/\/ \u4fee\u6539\u59d3\u540d,\u6216\uff1a(*b).name = \"LiJie\";\n    \/\/ \u6210\u7ee9\u4fdd\u6301\u4e0d\u53d8\uff0c\u65e0\u9700\u4fee\u6539\n}\n\nint main() {\n    struct student t = {10002, \"ZhangQi\", {93.00, 85.00, 87.00}};\n    \n    printf(\"\u4fee\u6539\u524d\u7684\u6570\u636e\uff1a\\n\");\n    printf(\"\u5b66\u53f7\uff1a%ld\\n\u59d3\u540d\uff1a%s\\n\u6210\u7ee9\uff1a%.2f, %.2f, %.2f\\n\\n\", \n           t.sno, t.name, t.score&#91;0], t.score&#91;1], t.score&#91;2]);\n    \n    fun(&amp;t);  \/\/ \u8c03\u7528\u51fd\u6570\u4fee\u6539\u6570\u636e\n    \n    printf(\"\u4fee\u6539\u540e\u7684\u6570\u636e\uff1a\\n\");\n    printf(\"\u5b66\u53f7\uff1a%ld\\n\u59d3\u540d\uff1a%s\\n\u6210\u7ee9\uff1a%.2f, %.2f, %.2f\\n\", \n           t.sno, t.name, t.score&#91;0], t.score&#91;1], t.score&#91;2]);\n    \n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p>\u4fee\u6539\u540e\u7684\u5b8c\u6574\u4ee3\u7801\u53ef\u4ee5\u662f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#include &lt;string.h>\n\ntypedef struct student {\n    long sno;\n    char name&#91;10];\n    float score&#91;3];\n} Student;  \/\/ \u521b\u5efa\u65b0\u7684\u7c7b\u578b\u540d\n\nvoid fun(Student *b) {  \/\/ \u73b0\u5728\u53ef\u4ee5\u7701\u7565 struct\n    b->sno = 10004;           \/\/ \u4fee\u6539\u5b66\u53f7,\u6216\uff1a(*b).sno = 10004;\n    strcpy(b->name, \"LiJie\"); \/\/ \u4fee\u6539\u59d3\u540d,\u6216\uff1a(*b).name = \"LiJie\";\n}\n\nint main() {\n    Student t = {10002, \"ZhangQi\", {93.00, 85.00, 87.00}};\n    fun(&amp;t);\n    printf(\"\u5b66\u53f7\uff1a%ld\\n\u59d3\u540d\uff1a%s\\n\u6210\u7ee9\uff1a%.2f, %.2f, %.2f\\n\", \n           t.sno, t.name, t.score&#91;0], t.score&#91;1], t.score&#91;2]);\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u4fee\u6539\u540e\uff0c\u4ee3\u7801\u770b\u8d77\u6765\u66f4\u7b80\u6d01\uff0c\u8fd9\u4e5f\u662f\u73b0\u4ee3C\u8bed\u8a00\u7f16\u7a0b\u4e2d\u66f4\u5e38\u7528\u7684\u65b9\u5f0f\u3002\u4e0d\u8fc7\u4e24\u79cd\u65b9\u5f0f\u90fd\u662f\u6b63\u786e\u7684\uff0c\u9009\u62e9\u54ea\u79cd\u4e3b\u8981\u53d6\u51b3\u4e8e\u7f16\u7a0b\u98ce\u683c\u548c\u9879\u76ee\u89c4\u8303\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u6709\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u58f0\u660e\u548c\u4f7f\u7528<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,5,8],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-c","category-it","category-cod"],"_links":{"self":[{"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":9,"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sncn.eu.org\/blog\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}