{"id":78191,"date":"2026-02-26T15:08:57","date_gmt":"2026-02-26T07:08:57","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/78191.html"},"modified":"2026-02-26T15:08:57","modified_gmt":"2026-02-26T07:08:57","slug":"%e5%8a%a8%e6%80%81%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86%ef%bc%88%e4%b8%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/78191.html","title":{"rendered":"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09"},"content":{"rendered":"<h2>\u4e00\u3001\u52a8\u6001\u5185\u5b58\u7ecf\u5178\u7b14\u8bd5\u9898\u5206\u6790<\/h2>\n<h3>1.1 \u9898\u76ee1&#xff1a;<\/h3>\n<p>void GetMemory(char* p)<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0p &#061; (char*)malloc(100);<br \/>\n}<br \/>\nvoid Test(void)<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0char* str &#061; NULL;<br \/>\n\u00a0\u00a0 \u00a0GetMemory(str);<br \/>\n\u00a0\u00a0 \u00a0strcpy(str, &#034;hello world&#034;);<br \/>\n\u00a0\u00a0 \u00a0printf(str);<br \/>\n}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8bf7\u95ee\u8fd0\u884cTest\u51fd\u6570\u4f1a\u6709\u4ec0\u4e48\u6837\u7684\u7ed3\u679c&#xff1f;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7a0b\u5e8f\u4f1a\u53d1\u751f\u5d29\u6e83\u3002\u539f\u56e0\u662f&#xff1a;str \u521d\u59cb\u4e3a NULL&#xff0c;\u8c03\u7528 GetMemory(str) \u65f6&#xff0c;\u7531\u4e8e\u53c2\u6570\u662f\u503c\u4f20\u9012&#xff0c;\u51fd\u6570\u5185\u90e8\u867d\u7136\u6267\u884c\u4e86 malloc(100)&#xff0c;\u4f46\u5e76\u6ca1\u6709\u6539\u53d8\u5916\u90e8\u7684 str&#xff0c;\u8fd4\u56de\u540e str \u4ecd\u7136\u662f NULL\u3002\u968f\u540e\u6267\u884c strcpy(str, &#034;hello world&#034;); \u65f6&#xff0c;\u76f8\u5f53\u4e8e\u5411\u7a7a\u6307\u9488\u5199\u5165\u6570\u636e&#xff0c;\u5c5e\u4e8e\u975e\u6cd5\u5185\u5b58\u8bbf\u95ee&#xff0c;\u7a0b\u5e8f\u4f1a\u76f4\u63a5\u5d29\u6e83\u6216\u5f02\u5e38\u7ec8\u6b62\u3002<\/p>\n<h3>1.2\u00a0\u9898\u76ee2&#xff1a;<\/h3>\n<p>char* GetMemory(void)<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0char p[] &#061; &#034;hello world&#034;;<br \/>\n\u00a0\u00a0 \u00a0return p;<br \/>\n}<br \/>\nvoid Test(void)<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0char* str &#061; NULL;<br \/>\n\u00a0\u00a0 \u00a0str &#061; GetMemory();<br \/>\n\u00a0\u00a0 \u00a0printf(str);<br \/>\n}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8bf7\u95ee\u8fd0\u884cTest\u51fd\u6570\u4f1a\u6709\u4ec0\u4e48\u6837\u7684\u7ed3\u679c&#xff1f;<\/p>\n<p>\u00a0\u00a0 \u00a0 \u00a0 \u00a0\u8f93\u51fa\u4e71\u7801\u3002\u539f\u56e0\u5728\u4e8e&#xff1a;GetMemory \u51fd\u6570\u4e2d\u5b9a\u4e49\u7684 char p[] &#061; &#034;hello world&#034;; \u662f\u4e00\u4e2a\u5c40\u90e8\u6570\u7ec4&#xff0c;\u5b58\u50a8\u5728\u51fd\u6570\u6808\u5e27\u91cc\u3002\u5f53\u51fd\u6570\u8fd4\u56de\u65f6&#xff0c;\u8fd9\u5757\u6808\u7a7a\u95f4\u5c31\u5931\u6548\u4e86&#xff0c;\u4f46\u51fd\u6570\u5374\u628a\u5b83\u7684\u5730\u5740\u8fd4\u56de\u7ed9\u4e86\u5916\u90e8\u3002\u4e8e\u662f str \u5f97\u5230\u7684\u662f\u4e00\u5757\u5df2\u7ecf\u88ab\u91ca\u653e&#xff08;\u65e0\u6548&#xff09;\u7684\u5185\u5b58\u5730\u5740&#xff0c;\u79f0\u4e3a\u91ce\u6307\u9488 \/ \u60ac\u7a7a\u6307\u9488\u3002\u968f\u540e\u6267\u884c printf(str); \u5c31\u662f\u5728\u8bbf\u95ee\u65e0\u6548\u5185\u5b58.<\/p>\n<h3>1.3 \u9898\u76ee3&#xff1a;<\/h3>\n<p>void GetMemory(char** p, int num)<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0*p &#061; (char*)malloc(num);<br \/>\n}<br \/>\nvoid Test(void)<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0char* str &#061; NULL;<br \/>\n\u00a0\u00a0 \u00a0GetMemory(&amp;str, 100);<br \/>\n\u00a0\u00a0 \u00a0strcpy(str, &#034;hello&#034;);<br \/>\n\u00a0\u00a0 \u00a0printf(str);<br \/>\n}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8bf7\u95ee\u8fd0\u884cTest\u51fd\u6570\u4f1a\u6709\u4ec0\u4e48\u6837\u7684\u7ed3\u679c&#xff1f;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8f93\u51fa &#034;hello&#034;\u3002\u51fd\u6570\u4e2d&#xff0c;str \u521d\u59cb\u4e3a NULL&#xff0c;\u901a\u8fc7\u8c03\u7528 GetMemory(&amp;str, 100) \u5728\u5806\u4e0a\u5206\u914d\u4e86 100 \u5b57\u8282\u5185\u5b58&#xff0c;\u5e76\u628a\u5730\u5740\u56de\u4f20\u7ed9 str\u3002\u968f\u540e&#xff0c;strcpy(str, &#034;hello&#034;) \u5c06\u5b57\u7b26\u4e32\u5199\u5165\u8fd9\u5757\u5185\u5b58&#xff0c;\u518d\u901a\u8fc7 printf(&#034;%s&#034;, str) \u6253\u5370\u51fa\u6765\u3002<\/p>\n<h3>1.4 \u9898\u76ee4&#xff1a;<\/h3>\n<p>void Test(void)<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0char* str &#061; (char*)malloc(100);<br \/>\n\u00a0\u00a0 \u00a0strcpy(str, &#034;hello&#034;);<br \/>\n\u00a0\u00a0 \u00a0free(str);<br \/>\n\u00a0\u00a0 \u00a0if (str !&#061; NULL)<br \/>\n\u00a0\u00a0 \u00a0{<br \/>\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0strcpy(str, &#034;world&#034;);<br \/>\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0printf(str);<br \/>\n\u00a0\u00a0 \u00a0}<br \/>\n}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8bf7\u95ee\u8fd0\u884cTest\u51fd\u6570\u4f1a\u6709\u4ec0\u4e48\u6837\u7684\u7ed3\u679c&#xff1f;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u4f1a\u8f93\u51faworld\u3002\u8fd9\u6bb5\u4ee3\u7801\u7684\u89e3\u6790\u5982\u4e0b&#xff1a;\u51fd\u6570 Test \u9996\u5148\u7528 malloc(100) \u4e3a\u6307\u9488 str \u5728\u5806\u4e0a\u5206\u914d\u4e86 100 \u5b57\u8282\u5185\u5b58&#xff0c;\u7136\u540e\u7528 strcpy(str, &#034;hello&#034;); \u5c06 &#034;hello&#034; \u5199\u5165\u8be5\u5185\u5b58\u3002\u63a5\u7740\u8c03\u7528 free(str); \u91ca\u653e\u5185\u5b58&#xff0c;\u4f46\u6307\u9488 str \u672c\u8eab\u4ecd\u7136\u4fdd\u5b58\u7740\u539f\u6765\u7684\u5730\u5740&#xff0c;\u8fd9\u65f6\u5b83\u6210\u4e3a \u60ac\u7a7a\u6307\u9488\u3002\u4e4b\u540e&#xff0c;\u4ee3\u7801\u5224\u65ad if (str !&#061; NULL)&#xff0c;\u6761\u4ef6\u6210\u7acb&#xff0c;\u56e0\u4e3a\u6307\u9488\u672c\u8eab\u975e\u7a7a&#xff0c;\u4f46\u5b83\u6307\u5411\u7684\u5185\u5b58\u5df2\u7ecf\u88ab\u91ca\u653e\u3002\u968f\u540e\u6267\u884c strcpy(str, &#034;world&#034;); \u548c printf(str)\u3002<\/p>\n<h2>\u4e8c\u3001\u67d4\u6027\u6570\u7ec4<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e5f\u8bb8\u4f60\u4ece\u6765\u6ca1\u6709\u542c\u8bf4\u8fc7\u67d4\u6027\u6570\u7ec4\u8fd9\u4e2a\u6982\u5ff5&#xff0c;\u4f46\u662f\u5b83\u786e\u5b9e\u662f\u5b58\u5728\u7684\u3002 C99\u4e2d&#xff0c;\u7ed3\u6784\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5141\u8bb8\u662f\u672a\u77e5\u5927\u5c0f\u7684\u6570\u7ec4&#xff0c;\u8fd9\u5c31\u53eb\u505a\u67d4\u6027\u6570\u7ec4\u6210\u5458\u3002 \u4f8b\u5982&#xff1a;<\/p>\n<p>struct st_type<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0int i;<br \/>\n\u00a0\u00a0 \u00a0int a[0];\/\/\u67d4\u6027\u6570\u7ec4\u6210\u5458<br \/>\n};<br \/>\n\u00a0<\/p>\n<h3>2.1\u67d4\u6027\u6570\u7ec4\u7684\u7279\u70b9<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7ed3\u6784\u4e2d\u7684\u67d4\u6027\u6570\u7ec4\u6210\u5458\u524d\u9762\u5fc5\u987b\u81f3\u5c11\u4e00\u4e2a\u5176\u4ed6\u6210\u5458\u3002sizeof\u8fd4\u56de\u7684\u8fd9\u79cd\u7ed3\u6784\u5927\u5c0f\u4e0d\u5305\u62ec\u67d4\u6027\u6570\u7ec4\u7684\u5185\u5b58\u3002\u5305\u542b\u67d4\u6027\u6570\u7ec4\u6210\u5458\u7684\u7ed3\u6784\u7528malloc()\u51fd\u6570\u8fdb\u884c\u5185\u5b58\u7684\u52a8\u6001\u5206\u914d&#xff0c;\u5e76\u4e14\u5206\u914d\u7684\u5185\u5b58\u5e94\u8be5\u5927\u4e8e\u7ed3\u6784\u7684\u5927\u5c0f&#xff0c;\u4ee5\u9002\u5e94\u67d4\u6027\u6570\u7ec4\u7684\u9884\u671f\u5927\u5c0f\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>typedef struct st_type<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0int i;<br \/>\n\u00a0\u00a0 \u00a0int a[0];\/\/\u67d4\u6027\u6570\u7ec4\u6210\u5458<\/p>\n<p>}type_a;<\/p>\n<p>int main()<br \/>\n{<br \/>\n\u00a0\u00a0 \u00a0printf(&#034;%d\\\\n&#034;, sizeof(type_a));\/\/\u8f93\u51fa\u7684\u662f4<br \/>\n\u00a0\u00a0 \u00a0return 0;<br \/>\n}<\/p>\n<h3>2.2\u67d4\u6027\u6570\u7ec4\u7684\u4f7f\u7528<\/h3>\n<p>\u4ee3\u78011&#xff1a;<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\nint main()<br \/>\n{<br \/>\nint i &#061; 0;<br \/>\ntype_a* p &#061; (type_a*)malloc(sizeof(type_a) &#043; 100 * sizeof(int));<br \/>\n\/\/\u4e1a\u52a1\u5904\u7406<\/p>\n<p>p-&gt;i &#061; 100;<br \/>\nfor (i &#061; 0; i &lt; 100; i&#043;&#043;)<br \/>\n{<br \/>\np-&gt;a[i] &#061; i;<br \/>\n}<br \/>\nfree(p);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u6837\u67d4\u6027\u6570\u7ec4\u6210\u5458a&#xff0c;\u76f8\u5f53\u4e8e\u83b7\u5f97\u4e86100\u4e2a\u6574\u578b\u5143\u7d20\u7684\u8fde\u7eed\u7a7a\u95f4\u3002\u8fd9\u9996\u5148&#xff0c;\u5b9a\u4e49\u4e86\u7ed3\u6784\u4f53 type_a&#xff0c;\u5176\u4e2d i \u662f\u666e\u901a\u6574\u578b\u6210\u5458&#xff0c;a[] \u662f\u7075\u6d3b\u6570\u7ec4\u6210\u5458&#xff0c;\u6ca1\u6709\u56fa\u5b9a\u957f\u5ea6\u3002main \u51fd\u6570\u4e2d&#xff0c;\u8c03\u7528 malloc(sizeof(type_a) &#043; 100 * sizeof(int)) \u4e3a\u7ed3\u6784\u4f53\u672c\u8eab\u52a0\u4e0a 100 \u4e2a\u6574\u6570\u7684\u6570\u7ec4\u7a7a\u95f4\u5728\u5806\u4e0a\u5206\u914d\u5185\u5b58&#xff0c;\u5e76\u5c06\u8fd4\u56de\u7684\u5730\u5740\u8d4b\u7ed9\u6307\u9488 p\u3002\u63a5\u7740\u68c0\u67e5 malloc \u662f\u5426\u6210\u529f&#xff0c;\u5982\u679c\u5931\u8d25\u76f4\u63a5\u8fd4\u56de\u3002\u7136\u540e\u901a\u8fc7 p-&gt;i &#061; 100; \u7ed9\u666e\u901a\u6210\u5458\u8d4b\u503c&#xff0c;\u518d\u7528\u5faa\u73af\u5c06 0~99 \u7684\u6574\u6570\u4f9d\u6b21\u5199\u5165\u7075\u6d3b\u6570\u7ec4 p-&gt;a[i]\u3002\u6700\u540e\u901a\u8fc7 printf \u6253\u5370\u7ed3\u6784\u4f53\u6210\u5458 i \u4ee5\u53ca\u6570\u7ec4\u9996\u5c3e\u5143\u7d20&#xff0c;\u9a8c\u8bc1\u6570\u636e\u6b63\u786e\u6027\u3002<\/p>\n<h3>2.3\u67d4\u6027\u6570\u7ec4\u7684\u4f18\u52bf<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e0a\u8ff0\u7684type_a \u7ed3\u6784\u4e5f\u53ef\u4ee5\u8bbe\u8ba1\u4e3a\u4e0b\u9762\u7684\u7ed3\u6784&#xff0c;\u4e5f\u80fd\u5b8c\u6210\u540c\u6837\u7684\u6548\u679c\u3002<\/p>\n<p>\u4ee3\u78012&#xff1a;<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\ntypedef struct st_type<br \/>\n{<br \/>\nint i;<br \/>\nint* p_a;<br \/>\n}type_a;<br \/>\nint main()<br \/>\n{<br \/>\ntype_a* p &#061; (type_a*)malloc(sizeof(type_a));<br \/>\np-&gt;i &#061; 100;<br \/>\np-&gt;p_a &#061; (int*)malloc(p-&gt;i * sizeof(int));<br \/>\n\/\/\u4e1a\u52a1\u5904\u7406<\/p>\n<p>for (int i &#061; 0; i &lt; 100; i&#043;&#043;)<br \/>\n{<br \/>\np-&gt;p_a[i] &#061; i;<br \/>\n}<br \/>\n\/\/\u91ca\u653e\u7a7a\u95f4<\/p>\n<p>free(p-&gt;p_a);<br \/>\np-&gt;p_a &#061; NULL;<br \/>\nfree(p);<br \/>\np &#061; NULL;<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u9996\u5148\u5b9a\u4e49\u7ed3\u6784\u4f53 type_a&#xff0c;\u5305\u542b\u4e00\u4e2a\u6574\u6570 i \u548c\u4e00\u4e2a\u6574\u578b\u6307\u9488 p_a&#xff0c;\u7528\u4e8e\u6307\u5411\u52a8\u6001\u5206\u914d\u7684\u6570\u7ec4\u3002\u5728 main \u4e2d&#xff0c;\u5148\u7528 malloc(sizeof(type_a)) \u4e3a\u7ed3\u6784\u4f53\u672c\u8eab\u5728\u5806\u4e0a\u5206\u914d\u5185\u5b58&#xff0c;\u5e76\u5c06\u8fd4\u56de\u7684\u5730\u5740\u8d4b\u7ed9\u6307\u9488 p\u3002\u7136\u540e\u8bbe\u7f6e p-&gt;i &#061; 100;&#xff0c;\u8868\u793a\u6570\u7ec4\u957f\u5ea6\u4e3a 100&#xff0c;\u518d\u901a\u8fc7 p-&gt;p_a &#061; malloc(p-&gt;i * sizeof(int)) \u4e3a\u6307\u9488\u6210\u5458 p_a \u5206\u914d 100 \u4e2a\u6574\u6570\u7684\u5185\u5b58\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u63a5\u7740\u901a\u8fc7\u5faa\u73af for (int i &#061; 0; i &lt; 100; i&#043;&#043;) p-&gt;p_a[i] &#061; i; \u5c06 0~99 \u7684\u503c\u5199\u5165\u6570\u7ec4&#xff0c;\u5b9e\u73b0\u4e1a\u52a1\u5904\u7406\u3002\u4f7f\u7528\u5b8c\u6570\u7ec4\u548c\u7ed3\u6784\u4f53\u540e&#xff0c;\u5148 free(p-&gt;p_a) \u91ca\u653e\u6570\u7ec4\u5185\u5b58&#xff0c;\u5e76\u5c06\u6307\u9488\u7f6e NULL \u907f\u514d\u60ac\u7a7a\u6307\u9488&#xff0c;\u518d free(p) \u91ca\u653e\u7ed3\u6784\u4f53\u672c\u8eab&#xff0c;\u540c\u65f6\u5c06 p \u7f6e NULL&#xff0c;\u4fdd\u8bc1\u5b89\u5168\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4e0a\u8ff0\u4ee3\u7801 1 \u548c \u4ee3\u7801 2 \u53ef\u4ee5\u5b8c\u6210\u540c\u6837\u7684\u529f\u80fd&#xff0c;\u4f46\u662f \u65b9\u6cd5 1 \u7684\u5b9e\u73b0\u6709\u4e24\u4e2a\u597d\u5904&#xff1a;<\/p>\n<p>1.\u65b9\u4fbf\u5185\u5b58\u91ca\u653e \u5982\u679c\u6211\u4eec\u7684\u4ee3\u7801\u662f\u5728\u4e00\u4e2a\u7ed9\u522b\u2f08\u7528\u7684\u51fd\u6570\u4e2d&#xff0c;\u4f60\u5728\u91cc\u9762\u505a\u4e86\u4e8c\u6b21\u5185\u5b58\u5206\u914d&#xff0c;\u5e76\u628a\u6574\u4e2a\u7ed3\u6784\u4f53\u8fd4\u56de\u7ed9\u7528\u6237\u3002\u7528\u6237\u8c03\u7528free\u53ef\u4ee5\u91ca\u653e\u7ed3\u6784\u4f53&#xff0c;\u4f46\u662f\u7528\u6237\u5e76\u4e0d\u77e5\u9053\u8fd9\u4e2a\u7ed3\u6784\u4f53\u5185\u7684\u6210\u5458\u4e5f\u9700\u8981free&#xff0c;\u6240\u4ee5\u4f60\u4e0d\u80fd\u6307\u671b\u7528\u6237\u6765\u53d1\u73b0\u8fd9\u4e2a\u4e8b\u3002\u6240\u4ee5&#xff0c;\u5982\u679c\u6211\u4eec\u628a\u7ed3\u6784\u4f53\u7684\u5185\u5b58\u4ee5\u53ca\u5176\u6210\u5458\u8981\u7684\u5185\u5b58\u2f00\u6b21\u6027\u5206\u914d\u597d\u4e86&#xff0c;\u5e76\u8fd4\u56de\u7ed9\u7528\u6237\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488&#xff0c;\u7528\u6237\u505a\u4e00\u6b21free\u5c31\u53ef\u4ee5\u628a\u6240\u6709\u7684\u5185\u5b58\u4e5f\u7ed9\u91ca\u653e\u6389\u3002<\/p>\n<p>2.\u8fd9\u6837\u6709\u5229\u4e8e\u8bbf\u95ee\u901f\u5ea6\u3002\u8fde\u7eed\u7684\u5185\u5b58\u6709\u76ca\u4e8e\u63d0\u9ad8\u8bbf\u95ee\u901f\u5ea6&#xff0c;\u4e5f\u6709\u76ca\u4e8e\u51cf\u5c11\u5185\u5b58\u788e\u7247\u3002<\/p>\n<h2>\u4e09\u3001\u603b\u7ed3C\/C&#043;&#043;\u4e2d\u7a0b\u5e8f\u5185\u5b58\u533a\u57df\u5212\u5206<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"853\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226070856-699ff1886b42d.jpg\" width=\"1280\" \/><\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0C\/C&#043;&#043;\u7a0b\u5e8f\u5185\u5b58\u5206\u914d\u7684\u51e0\u4e2a\u533a\u57df&#xff1a;<\/p>\n<p>1. \u6808\u533a&#xff08;stack&#xff09;&#xff1a;\u5728\u6267\u884c\u51fd\u6570\u65f6&#xff0c;\u51fd\u6570\u5185\u5c40\u90e8\u53d8\u91cf\u7684\u5b58\u50a8\u5355\u5143\u90fd\u53ef\u4ee5\u5728\u6808\u4e0a\u521b\u5efa&#xff0c;\u51fd\u6570\u6267\u884c\u7ed3\u675f\u65f6 \u8fd9\u4e9b\u5b58\u50a8\u5355\u5143\u81ea\u52a8\u88ab\u91ca\u653e\u3002\u6808\u5185\u5b58\u5206\u914d\u8fd0\u7b97\u5185\u7f6e\u4e8e\u5904\u7406\u5668\u7684\u6307\u4ee4\u96c6\u4e2d&#xff0c;\u6548\u7387\u5f88\u9ad8&#xff0c;\u4f46\u662f\u5206\u914d\u7684\u5185\u5b58\u5bb9\u91cf\u6709\u9650\u3002\u6808\u533a\u4e3b\u8981\u5b58\u653e\u8fd0\u884c\u51fd\u6570\u800c\u5206\u914d\u7684\u5c40\u90e8\u53d8\u91cf\u3001\u51fd\u6570\u53c2\u6570\u3001\u8fd4\u56de\u6570\u636e\u3001\u8fd4\u56de\u5730\u5740\u7b49\u3002\u00a0<\/p>\n<p>2. \u5806\u533a&#xff08;heap&#xff09;&#xff1a;\u4e00\u822c\u7531\u7a0b\u5e8f\u5458\u5206\u914d\u91ca\u653e&#xff0c;\u82e5\u7a0b\u5e8f\u5458\u4e0d\u91ca\u653e&#xff0c;\u7a0b\u5e8f\u7ed3\u675f\u65f6\u53ef\u80fd\u7531OS\u56de\u6536\u3002\u5206\u914d\u65b9 \u5f0f\u7c7b\u4f3c\u4e8e\u94fe\u8868\u3002<\/p>\n<p>3. \u6570\u636e\u6bb5&#xff08;\u9759\u6001\u533a&#xff09;&#xff1a;&#xff08;static&#xff09;\u5b58\u653e\u5168\u5c40\u53d8\u91cf\u3001\u9759\u6001\u6570\u636e\u3002\u7a0b\u5e8f\u7ed3\u675f\u540e\u7531\u7cfb\u7edf\u91ca\u653e\u3002<\/p>\n<p>4. \u4ee3\u7801\u6bb5&#xff1a;\u5b58\u653e\u51fd\u6570\u4f53&#xff08;\u7c7b\u6210\u5458\u51fd\u6570\u548c\u5168\u5c40\u51fd\u6570&#xff09;\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u52a8\u6001\u5185\u5b58\u7ecf\u5178\u7b14\u8bd5\u9898\u5206\u67901.1 \u9898\u76ee1&#xff1a;void GetMemory(char* p)<br \/>\n{p  (char*)malloc(100);<br \/>\n}<br \/>\nvoid Test(void)<br \/>\n{char* str  NULL;GetMemory(str);strcpy(str, \\&#8221;hello world\\&#8221;);printf(str);<br \/>\n}\u8bf7\u95ee\u8fd0\u884cTest\u51fd\u6570\u4f1a\u6709\u4ec0\u4e48\u6837\u7684\u7ed3\u679c&#xff1f;\u7a0b\u5e8f\u4f1a\u53d1\u751f\u5d29\u6e83\u3002\u539f\u56e0\u662f&#xff1a;str \u521d\u59cb\u4e3a NULL&#xff0c;\u8c03\u7528 GetMe<\/p>\n","protected":false},"author":2,"featured_media":78190,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[8624,174,427],"topic":[],"class_list":["post-78191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-8624","tag-c","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/78191.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u52a8\u6001\u5185\u5b58\u7ecf\u5178\u7b14\u8bd5\u9898\u5206\u67901.1 \u9898\u76ee1&#xff1a;void GetMemory(char* p) {p (char*)malloc(100); } void Test(void) {char* str NULL;GetMemory(str);strcpy(str, &quot;hello world&quot;);printf(str); }\u8bf7\u95ee\u8fd0\u884cTest\u51fd\u6570\u4f1a\u6709\u4ec0\u4e48\u6837\u7684\u7ed3\u679c&#xff1f;\u7a0b\u5e8f\u4f1a\u53d1\u751f\u5d29\u6e83\u3002\u539f\u56e0\u662f&#xff1a;str \u521d\u59cb\u4e3a NULL&#xff0c;\u8c03\u7528 GetMe\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/78191.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-26T07:08:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226070856-699ff1886b42d.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78191.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/78191.html\",\"name\":\"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-26T07:08:57+00:00\",\"dateModified\":\"2026-02-26T07:08:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/78191.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/78191.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78191.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/78191.html","og_locale":"zh_CN","og_type":"article","og_title":"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u52a8\u6001\u5185\u5b58\u7ecf\u5178\u7b14\u8bd5\u9898\u5206\u67901.1 \u9898\u76ee1&#xff1a;void GetMemory(char* p) {p (char*)malloc(100); } void Test(void) {char* str NULL;GetMemory(str);strcpy(str, \"hello world\");printf(str); }\u8bf7\u95ee\u8fd0\u884cTest\u51fd\u6570\u4f1a\u6709\u4ec0\u4e48\u6837\u7684\u7ed3\u679c&#xff1f;\u7a0b\u5e8f\u4f1a\u53d1\u751f\u5d29\u6e83\u3002\u539f\u56e0\u662f&#xff1a;str \u521d\u59cb\u4e3a NULL&#xff0c;\u8c03\u7528 GetMe","og_url":"https:\/\/www.wsisp.com\/helps\/78191.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-26T07:08:57+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226070856-699ff1886b42d.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/78191.html","url":"https:\/\/www.wsisp.com\/helps\/78191.html","name":"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-26T07:08:57+00:00","dateModified":"2026-02-26T07:08:57+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/78191.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/78191.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/78191.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u52a8\u6001\u5185\u5b58\u7ba1\u7406\uff08\u4e0b\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=78191"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78191\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/78190"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=78191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=78191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=78191"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=78191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}