\u7ed3\u6784\u4f53\u4e2d\u5b58\u5728\u6307\u9488\u6210\u5458\u53d8\u91cf\u65f6<\/strong><\/span><\/div>\n\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
\/\/\u5728win10_64\u4f4d+vs2017\r\n\/\/\u6765\u6e90\uff1a\u6280\u672f\u8ba9\u68a6\u60f3\u66f4\u4f1f\u5927\r\n\/\/\u4f5c\u8005\uff1a\u674e\u8096\u9065\r\n#include \r\n#include \r\n#include \r\ntypedef struct {\r\n char *name;\r\n int age;\r\n}Member;\r\nint main() {\r\n Member Member1, Member2;\r\n Member1.name = malloc(sizeof(char) * 64);\r\n if (NULL == Member1.name)\r\n {\r\n printf(\"malloc failed\\n\");\r\n }\r\n memset(Member1.name, 0, 64);\r\n \/\/strcpy(Member1.name, \"LiMing\");\r\n snprintf(Member1.name, 64, \"LiMing\");\r\n Member1.age = 18;\r\n Member2 = Member1;\/*\u62f7\u8d1d*\/\r\n snprintf(Member2.name, 64, \"LiXiaoYao\");\r\n Member2.age = 29;\r\n printf(\"%s, %d\\n\", Member1.name, Member1.age);\r\n if (NULL != Member1.name) {\r\n free(Member1.name);\r\n Member1.name = NULL;\r\n }\r\n system(\"pause\");\r\n return 0;\r\n}\r\n<\/pre>\n\u8fd0\u884c\u5982\u4e0b\uff1a<\/p>\n
<\/p>\n
\u4ece\u4e2d\u6211\u4eec\u770b\u5230\uff0c\u6539\u53d8Member2\u7684\u503c\uff0cMember1\u7684\u503c\u4e5f\u6539\u53d8\u4e86\uff0c\u8fd9\u8bf4\u660e\u4e00\u7247\u7a7a\u95f4\u88ab\u4e24\u4e2a\u4e0d\u540c\u7684\u5b50\u5bf9\u8c61\u5171\u4eab\u4e86\uff0c\u6539\u53d8\u4e00\u4e2a\u5bf9\u8c61\u7684\u503c\u53e6\u5916\u4e00\u4e2a\u4e5f\u4f1a\u968f\u4e4b\u6539\u53d8\u3002<\/p>\n
\u6211\u4eec\u6539\u53d8Member2\u5199\u6cd5\uff0c\u7533\u8bf7\u5185\u5b58\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
\/\/\u5728win10_64\u4f4d+vs2017\r\n\/\/\u6765\u6e90\uff1a\u6280\u672f\u8ba9\u68a6\u60f3\u66f4\u4f1f\u5927\r\n\/\/\u4f5c\u8005\uff1a\u674e\u8096\u9065\r\n#include \r\n#include \r\n#include \r\ntypedef struct {\r\n char *name;\r\n int age;\r\n}Member;\r\nint main() {\r\n Member Member1;\r\n Member1.name = malloc(sizeof(char) * 64);\r\n if (NULL == Member1.name)\r\n {\r\n printf(\"malloc failed\\n\");\r\n }\r\n memset(Member1.name, 0, 64);\r\n \/\/strcpy(Member1.name, \"LiMing\");\r\n snprintf(Member1.name, 64, \"LiMing\");\r\n Member1.age = 18; \r\n Member Member2;\r\n Member2.name = malloc(sizeof(char) * 64);\r\n if (NULL == Member2.name)\r\n {\r\n printf(\"malloc failed\\n\");\r\n }\r\n memset(Member2.name, 0, 64);\r\n \/\/strcpy(Member2.name, \"LiMing\");\r\n snprintf(Member2.name, 64, \"LiXiaoYao\");\r\n Member2.age = 29;\r\n Member1 = Member2;\r\n printf(\"%s, %d\\n\", Member2.name, Member2.age\r\n if (NULL != Member1.name) {\r\n free(Member1.name);\r\n Member1.name = NULL;\r\n }\r\n if (NULL != Member2.name) {\r\n free(Member2.name);\r\n Member2.name = NULL;\r\n }\r\n system(\"pause\");\r\n return 0;\r\n}\r\n<\/pre>\n\u8fd0\u884c\u5982\u4e0b\uff1a<\/p>\n
<\/p>\n
\u4ece\u4e2d\u6211\u4eec\u770b\u5230\uff0c\u5f53\u6570\u636e\u6210\u5458\u4e2d\u6709\u6307\u9488\u65f6\uff0c\u4e24\u4e2a\u7c7b\u4e2d\u7684\u4e24\u4e2a\u6307\u9488\u5c06\u6307\u5411\u540c\u4e00\u4e2a\u5730\u5740\uff0c\u5f53\u5bf9\u8c61\u5feb\u7ed3\u675f\u65f6\uff0c\u4f1a\u8c03\u7528\u4e24\u6b21free\u51fd\u6570\uff0c\u6b64\u65f6Member2\u5df2\u7ecf\u662f\u91ce\u6307\u9488\uff08\u56fe\u4e2d\u6709X\u7684\u9519\u8bef\u6807\u5fd7\uff09\uff0c\u8fd9\u4e2a\u91ce\u6307\u9488\u6307\u5411\u7684\u5185\u5b58\u7a7a\u95f4\u5df2\u7ecf\u88ab\u91ca\u653e\u6389\uff0c\u518d\u6b21\u91ca\u653e\u4f1a\u62a5\u5f02\u5e38\u9519\u8bef\uff0c\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5c31\u8981\u6d89\u53ca\u5230\u6df1\u62f7\u8d1d\u4e86\u3002<\/p>\n
\u6df1\u62f7\u8d1d<\/strong><\/div>\n\u6df1\u62f7\u8d1d\u9664\u4e86\u62f7\u8d1d\u5176\u6210\u5458\u672c\u8eab\u7684\u503c\u4e4b\u5916\uff0c\u8fd8\u62f7\u8d1d\u6210\u5458\u6307\u5411\u7684\u52a8\u6001\u5185\u5b58\u533a\u57df\u5185\u5bb9\uff0c\u6df1\u62f7\u8d1d\u4f1a\u5728\u5806\u5185\u5b58\u4e2d\u53e6\u5916\u7533\u8bf7\u7a7a\u95f4\u6765\u50a8\u5b58\u6570\u636e\u3002<\/p>\n
\u89e3\u51b3\u7684\u601d\u8def\u662f\u5728\u91ca\u653e\u6389\u88ab\u8d4b\u503c\u6307\u9488\u53d8\u91cf\u7684\u65e7\u6307\u5411\u5185\u5b58\u65f6\uff0c\u91cd\u65b0\u5bf9\u5176\u5f00\u8f9f\u65b0\u5185\u5b58\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4e24\u4e2a\u7ed3\u6784\u4f53\u4e2d\u6307\u9488\u5730\u5740\u4e0d\u540c\uff0c\u4f46\u662f\u6307\u5411\u7684\u5185\u5bb9\u662f\u4e00\u81f4\u7684\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
\/\/\u5728win10_64\u4f4d+vs2017\r\n\/\/\u6765\u6e90\uff1a\u6280\u672f\u8ba9\u68a6\u60f3\u66f4\u4f1f\u5927\r\n\/\/\u4f5c\u8005\uff1a\u674e\u8096\u9065\r\n#include \r\n#include \r\ntypedef struct {\r\n char *name;\r\n int age;\r\n}Member;\r\nint main() {\r\n Member Member1;\r\n Member1.name = malloc(sizeof(char) * 64);\r\n if (NULL == Member1.name)\r\n {\r\n printf(\"malloc failed\\n\");\r\n }\r\n memset(Member1.name, 0, 64);\r\n \/\/strcpy(Member1.name, \"LiMing\");\r\n snprintf(Member1.name, 64, \"LiMing\");\r\n Member1.age = 18;\r\n Member Member2;\r\n Member2.name = malloc(sizeof(char) * 64);\r\n if (NULL == Member2.name)\r\n {\r\n printf(\"malloc failed\\n\");\r\n }\r\n memset(Member2.name, 0, 64);\r\n \/\/strcpy(Member2.name, \"LiMing\");\r\n snprintf(Member2.name, 64, \"LiXiaoYao\");\r\n Member2.age = 29;\r\n if (Member1.name != NULL) {\r\n free(Member1.name);\r\n Member1.name = NULL;\r\n }\r\n Member1.name = malloc(strlen(Member2.name) + 1);\r\n strcpy(Member1.name, Member2.name);\r\n printf(\"%s, %d\\n\", Member1.name, Member1.age);\r\n if (NULL != Member1.name) {\r\n free(Member1.name);\r\n Member1.name = NULL;\r\n }\r\n if (NULL != Member2.name) {\r\n free(Member2.name);\r\n Member2.name = NULL;\r\n }\r\n system(\"pause\");\r\n return 0;\r\n}\r\n<\/pre>\n\u8fd0\u884c\u5982\u4e0b\uff1a<\/p>\n
<\/p>\n
\u7ed3\u8bba<\/strong><\/div>\n\u4f7f\u7528C\u8bed\u8a00\u6765\u8bf4\uff0c\u6df1\u62f7\u8d1d\u6d45\u62f7\u8d1d\u7684\u6982\u5ff5\u6211\u4eec\u4e0d\u9700\u8981\u6df1\u7a76\uff0c\u5728\u8fdb\u884c\u7ed3\u6784\u4f53\u62f7\u8d1d\u7684\u65f6\u5019\uff0c\u7ed3\u6784\u4f53\u6210\u5458\u662f\u975e\u6307\u9488\u7684\u8bdd\uff0c\u90a3\u4e48\u76f4\u63a5\u8d4b\u503c\u662f\u6ca1\u6709\u4efb\u4f55\u95ee\u9898\u7684\uff0c\u5efa\u8bae\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\uff0c\u907f\u514d\u6d45\u62f7\u8d1d\u8fd9\u7c7b\u4e0d\u6613\u53d1\u73b0\u7684\u9519\u8bef\u4ea7\u751f\u3002<\/p>\n
\u5982\u679c\u6210\u5458\u6709\u6307\u9488\u7c7b\u578b\uff0c\u6211\u4eec\u5c31\u9700\u8981\u91cd\u5199\u62f7\u8d1d\u51fd\u6570\uff0c\u81ea\u5df1\u5b9a\u4e49\u62f7\u8d1d\u884c\u4e3a\u4e86\uff0c\u8fd9\u4e00\u70b9\u6211\u4eec\u9700\u8981\u5c24\u4e3a\u6ce8\u610f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
C\u8bed\u8a00\u4e2d\u7684\u6d45\u62f7\u8d1d\u662f\u6307\u5728\u62f7\u8d1d\u8fc7\u7a0b\u4e2d\uff0c\u5bf9\u4e8e\u6307\u9488\u578b\u6210\u5458\u53d8\u91cf\u53ea\u62f7\u8d1d\u6307\u9488\u672c\u8eab\uff0c\u800c\u4e0d\u62f7\u8d1d\u6307\u9488\u6240\u6307\u5411\u7684\u76ee\u6807\uff0c\u5b83\u6309\u5b57\u8282\u590d\u5236\u7684\u3002 […]<\/p>\n","protected":false},"author":1898,"featured_media":256526,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[548],"class_list":["post-254231","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-c"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=254231"}],"version-history":[{"count":11,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254231\/revisions"}],"predecessor-version":[{"id":258557,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254231\/revisions\/258557"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/256526"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=254231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=254231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=254231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}