{"id":76580,"date":"2026-02-22T21:09:25","date_gmt":"2026-02-22T13:09:25","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/76580.html"},"modified":"2026-02-22T21:09:25","modified_gmt":"2026-02-22T13:09:25","slug":"%e5%b5%8c%e5%85%a5%e5%bc%8f%e7%9f%a5%e8%af%86%e7%82%b9%e5%ad%a6%e4%b9%a0%e7%af%87%e4%b8%80%ef%bc%88c-c%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/76580.html","title":{"rendered":"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\uff09"},"content":{"rendered":"<\/p>\n<h4>\u5173\u952e\u5b57<\/h4>\n<ul>\n<li>C\u8bed\u8a00\u5b8f\u4e2d\u201c#\u201d\u548c\u201c##\u201d\u7684\u7528\u6cd5<\/li>\n<li>\u5173\u952e\u5b57volatile\u6709\u4ec0\u4e48\u542b\u4e49&#xff1f;\u5e76\u4e3e\u51fa\u4e09\u4e2a\u4e0d\u540c\u7684\u4f8b\u5b50&#xff1f;<\/li>\n<li>\u5173\u952e\u5b57static\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;<\/li>\n<li>\u5728C\u8bed\u8a00\u4e2d&#xff0c;\u4e3a\u4ec0\u4e48static\u53d8\u91cf\u53ea\u521d\u59cb\u5316\u4e00\u6b21&#xff1f;<\/li>\n<li>extern \u201dC\u201c\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;<\/li>\n<li>const\u6709\u4ec0\u4e48\u4f5c\u7528&#xff1f;<\/li>\n<li>\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f7f\u7528const\u5173\u952e\u5b57&#xff1f;<\/li>\n<li>new\/delete\u4e0emalloc\/free\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;<\/li>\n<li>strlen(&#034;\\\\0&#034;) &#061; &#xff1f; sizeof(&#034;\\\\0&#034;) &#061; ?<\/li>\n<li>sizeof\u4e0estrlen\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;<\/li>\n<li>\u4e0d\u4f7f\u7528sizeof&#xff0c;\u5982\u4f55\u6c42int\u5360\u7528\u7684\u5b57\u8282\u6570&#xff1f;<\/li>\n<li>C\u8bed\u8a00\u4e2dstruct\u4e0eunion\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;<\/li>\n<li>\u5de6\u503c\u548c\u53f3\u503c\u662f\u4ec0\u4e48&#xff1f;<\/li>\n<li>\u4ec0\u4e48\u662f\u77ed\u8def\u6c42\u503c&#xff1f;<\/li>\n<li>&#043;&#043;a\u548ca&#043;&#043;\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;\u4e24\u8005\u662f\u5982\u4f55\u5b9e\u73b0\u7684&#xff1f;<\/li>\n<\/ul>\n<h2>C\u8bed\u8a00\u5b8f\u4e2d\u201c#\u201d\u548c\u201c##\u201d\u7684\u7528\u6cd5<\/h2>\n<p>1.\u201c#\u201d- \u5b57\u7b26\u4e32\u5316\u64cd\u4f5c\u7b26<\/p>\n<p>\u4f5c\u7528&#xff1a;\u5c06\u5b8f\u5b9a\u4e49\u4e2d\u7684\u4f20\u5165\u53c2\u6570\u540d\u8f6c\u6362\u6210\u7528\u4e00\u5bf9\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u53c2\u6570\u540d\u5b57\u7b26\u4e32\u3002\u5176\u53ea\u80fd\u7528\u4e8e\u6709\u4f20\u5165\u53c2\u6570\u7684\u5b8f\u5b9a\u4e49\u4e2d&#xff0c;\u4e14\u5fc5\u987b\u7f6e\u4e8e\u5b8f\u5b9a\u4e49\u4f53\u4e2d\u7684\u53c2\u6570\u540d\u524d\u3002<\/p>\n<p>\u4f8b&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">text_1<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>str<span class=\"token punctuation\">)<\/span><span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><\/span><span class=\"token string\">&#034;the input string is :\\\\t%s\\\\n&#034;<\/span><span class=\"token expression\"><span class=\"token punctuation\">,<\/span>#str<span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">text_2<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>str<span class=\"token punctuation\">)<\/span>#str<\/span><\/span><\/p>\n<p>\u5f53\u4f7f\u7528\u8be5\u5b8f\u5b9a\u4e49\u65f6&#xff1a;<\/p>\n<p><span class=\"token function\">text_1<\/span><span class=\"token punctuation\">(<\/span>abc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u5728\u7f16\u8bd1\u65f6\u5c06\u4f1a\u5c55\u5f00\u6210&#xff1a;printf(&#034;the input string is :\\\\t%s\\\\n&#034;,&#034;abc&#034;)<\/span><br \/>\nstring cstr <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">text_2<\/span><span class=\"token punctuation\">(<\/span>abc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u5c06\u4f1a\u5c55\u6210&#xff1a;string cstr &#061; &#034;abc&#034;<\/span><\/p>\n<p>2.\u201c##\u201d- \u7b26\u53f7\u8fde\u63a5\u64cd\u4f5c\u7b26<\/p>\n<p>\u4f5c\u7528&#xff1a;\u5c06\u5b8f\u5b9a\u4e49\u7684\u591a\u4e2a\u5f62\u53c2\u8f6c\u6362\u6210\u4e00\u4e2a\u5b9e\u9645\u53c2\u6570\u540d\u3002<\/p>\n<p>\u4f8b&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">text<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span>text_<\/span><span class=\"token punctuation\">##<\/span><span class=\"token expression\">n<\/span><\/span><\/p>\n<p>\u4f7f\u7528&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> num <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">text<\/span><span class=\"token punctuation\">(<\/span>str<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u5c06\u4f1a\u6269\u5c55\u6210 int num &#061; text_str<\/span><\/p>\n<p>\u6ce8\u610f&#xff1a; a.\u5f53\u7528##\u8fde\u63a5\u5f62\u53c2\u65f6&#xff0c;##\u524d\u540e\u7684\u7a7a\u683c\u53ef\u6709\u53ef\u65e0\u3002<\/p>\n<p>\u5982&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">test<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span>num <\/span><span class=\"token punctuation\">##<\/span> <span class=\"token expression\">n<\/span><\/span><br \/>\n<span class=\"token comment\">\/\/\u76f8\u5f53\u4e8e #define test(n)num##n<\/span><\/p>\n<p>b.\u8fde\u63a5\u540e\u7684\u5b9e\u9645\u53c2\u6570\u540d&#xff0c;\u5fc5\u987b\u4e3a\u5b9e\u9645\u5b58\u5728\u7684\u53c2\u6570\u540d\u6216\u662f\u7f16\u8bd1\u5668\u5df2\u77e5\u7684\u5b8f\u5b9a\u4e49\u3002<\/p>\n<p>c. \u5982\u679c##\u540e\u7684\u53c2\u6570\u672c\u8eab\u4e5f\u662f\u4e00\u4e2a\u5b8f\u7684\u8bdd&#xff0c;##\u4f1a\u963b\u6b62\u8fd9\u4e2a\u5b8f\u7684\u5c55\u5f00\u3002<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;string.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span><span class=\"token macro-name function\">STRCPY<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span><span class=\"token function\">strcpy<\/span><span class=\"token punctuation\">(<\/span>a <\/span><span class=\"token punctuation\">##<\/span> <span class=\"token expression\">_p<span class=\"token punctuation\">,<\/span> #b<span class=\"token punctuation\">)<\/span><\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">char<\/span> var1_p<span class=\"token punctuation\">[<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">char<\/span> var2_p<span class=\"token punctuation\">[<\/span><span class=\"token number\">30<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">strcpy<\/span><span class=\"token punctuation\">(<\/span>var1_p<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;aaaa&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">strcpy<\/span><span class=\"token punctuation\">(<\/span>var2_p<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;bbbb&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">STRCPY<\/span><span class=\"token punctuation\">(<\/span>var1<span class=\"token punctuation\">,<\/span> var2<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">STRCPY<\/span><span class=\"token punctuation\">(<\/span>var2<span class=\"token punctuation\">,<\/span> var1<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;var1 &#061; %s\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> var1_p<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;var2 &#061; %s\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> var2_p<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/STRCPY(STRCPY(var1,var2),var2);<\/span><br \/>\n<span class=\"token comment\">\/\/\u8fd9\u91cc\u662f\u5426\u4f1a\u5c55\u5f00\u4e3a&#xff1a; strcpy(strcpy(var1_p,&#034;var2&#034;)_p,&#034;var2\u201c&#xff09;&#xff1f;\u7b54\u6848\u662f\u5426\u5b9a\u7684&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/\/\u5c55\u5f00\u7ed3\u679c\u5c06\u662f&#xff1a; strcpy(STRCPY(var1,var2)_p,&#034;var2&#034;)<\/span><br \/>\n<span class=\"token comment\">\/\/## \u963b\u6b62\u4e86\u53c2\u6570\u7684\u5b8f\u5c55\u5f00!\u5982\u679c\u5b8f\u5b9a\u4e49\u91cc\u6ca1\u6709\u7528\u5230 # \u548c ##, \u5b8f\u5c06\u4f1a\u5b8c\u5168\u5c55\u5f00<\/span><br \/>\n<span class=\"token comment\">\/\/ \u628a\u6ce8\u91ca\u6253\u5f00\u7684\u8bdd&#xff0c;\u4f1a\u62a5\u9519:implicit declaration of function &#039;STRCPY&#039;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<p>var1 <span class=\"token operator\">&#061;<\/span> var2<br \/>\nvar2 <span class=\"token operator\">&#061;<\/span> var1<\/p>\n<h2>\u5173\u952e\u5b57volatile\u6709\u4ec0\u4e48\u542b\u4e49&#xff1f;\u5e76\u4e3e\u51fa\u4e09\u4e2a\u4e0d\u540c\u7684\u4f8b\u5b50&#xff1f;<\/h2>\n<li>\u5e76\u884c\u8bbe\u5907\u7684\u786c\u4ef6\u5bc4\u5b58\u5668\u3002\u5b58\u50a8\u5668\u6620\u5c04\u7684\u786c\u4ef6\u5bc4\u5b58\u5668\u901a\u5e38\u52a0volatile&#xff0c;\u56e0\u4e3a\u5bc4\u5b58\u5668\u968f\u65f6\u53ef\u4ee5\u88ab\u5916\u8bbe\u786c\u4ef6\u4fee\u6539\u3002\u5f53\u58f0\u660e\u6307\u5411\u8bbe\u5907\u5bc4\u5b58\u5668\u7684\u6307\u9488\u65f6\u4e00\u5b9a\u8981\u7528volatile&#xff0c;\u5b83\u4f1a\u544a\u8bc9\u7f16\u8bd1\u5668\u4e0d\u8981\u5bf9\u5b58\u50a8\u5728\u8fd9\u4e2a\u5730\u5740\u7684\u6570\u636e\u8fdb\u884c\u5047\u8bbe\u3002<\/li>\n<li>\u4e00\u4e2a\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\u4e2d\u4fee\u6539\u7684\u4f9b\u5176\u4ed6\u7a0b\u5e8f\u68c0\u6d4b\u7684\u53d8\u91cf\u3002volatile\u63d0\u9192\u7f16\u8bd1\u5668&#xff0c;\u5b83\u540e\u9762\u6240\u5b9a\u4e49\u7684\u53d8\u91cf\u968f\u65f6\u90fd\u6709\u53ef\u80fd\u6539\u53d8\u3002\u56e0\u6b64\u7f16\u8bd1\u540e\u7684\u7a0b\u5e8f\u6bcf\u6b21\u9700\u8981\u5b58\u50a8\u6216\u8bfb\u53d6\u8fd9\u4e2a\u53d8\u91cf\u7684\u65f6\u5019&#xff0c;\u90fd\u4f1a\u76f4\u63a5\u4ece\u53d8\u91cf\u5730\u5740\u4e2d\u8bfb\u53d6\u6570\u636e\u3002\u5982\u679c\u6ca1\u6709volatile\u5173\u952e\u5b57&#xff0c;\u5219\u7f16\u8bd1\u5668\u53ef\u80fd\u4f18\u5316\u8bfb\u53d6\u548c\u5b58\u50a8&#xff0c;\u53ef\u80fd\u6682\u65f6\u4f7f\u7528\u5bc4\u5b58\u5668\u4e2d\u7684\u503c&#xff0c;\u5982\u679c\u8fd9\u4e2a\u53d8\u91cf\u7531\u522b\u7684\u7a0b\u5e8f\u66f4\u65b0\u4e86\u7684\u8bdd&#xff0c;\u5c06\u51fa\u73b0\u4e0d\u4e00\u81f4\u7684\u73b0\u8c61\u3002<\/li>\n<li>\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u88ab\u51e0\u4e2a\u4efb\u52a1\u5171\u4eab\u7684\u53d8\u91cf\u3002\u5355\u5730\u8bf4\u5c31\u662f\u9632\u6b62\u7f16\u8bd1\u5668\u5bf9\u4ee3\u7801\u8fdb\u884c\u4f18\u5316.\u6bd4\u5982\u5982\u4e0b\u7a0b\u5e8f&#xff1a;<\/li>\n<p>XBYTE<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">0x55<\/span><span class=\"token punctuation\">;<\/span><br \/>\nXBYTE<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">0x56<\/span><span class=\"token punctuation\">;<\/span><br \/>\nXBYTE<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">0x57<\/span><span class=\"token punctuation\">;<\/span><br \/>\nXBYTE<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">0x58<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5bf9\u5916\u90e8\u786c\u4ef6\u800c\u8a00&#xff0c;\u4e0a\u8ff0\u56db\u6761\u8bed\u53e5\u5206\u522b\u4ee3\u8868\u4e0d\u540c\u7684\u64cd\u4f5c&#xff0c;\u4f1a\u4ea7\u751f\u56db\u79cd\u4e0d\u540c\u7684\u52a8\u4f5c&#xff0c;\u4f46\u662f\u7f16\u8bd1\u5668\u5374\u4f1a\u5bf9\u4e0a\u8ff0\u56db\u6761\u8bed\u53e5\u8fdb\u884c\u4f18\u5316&#xff0c;\u8ba4\u4e3a\u53ea\u6709XBYTE[2]&#061;0x58;&#xff08;\u5373\u5ffd\u7565\u524d\u4e09\u6761\u8bed\u53e5&#xff0c;\u53ea\u4ea7\u751f\u4e00\u6761\u673a\u5668\u4ee3\u7801&#xff09;\u3002\u5982\u679c\u952e\u5165volatile&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u9010\u4e00\u7684\u8fdb\u884c\u7f16\u8bd1\u5e76\u4ea7\u751f\u76f8\u5e94\u7684\u673a\u5668\u4ee3\u7801&#xff08;\u4ea7\u751f\u56db\u6761\u4ee3\u7801&#xff09;\u3002<\/p>\n<h2>\u5173\u952e\u5b57static\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<li>\u5728\u51fd\u6570\u4f53&#xff0c;\u53ea\u4f1a\u88ab\u521d\u59cb\u5316\u4e00\u6b21&#xff0c;\u4e00\u4e2a\u88ab\u58f0\u660e\u4e3a\u9759\u6001\u7684\u53d8\u91cf\u5728\u8fd9\u4e00\u51fd\u6570\u88ab\u8c03\u7528\u8fc7\u7a0b\u4e2d\u7ef4\u6301\u5176\u503c\u4e0d\u53d8\u3002<\/li>\n<li>\u5728\u6a21\u5757\u5185&#xff08;\u4f46\u5728\u51fd\u6570\u4f53\u5916&#xff09;&#xff0c;\u4e00\u4e2a\u88ab\u58f0\u660e\u4e3a\u9759\u6001\u7684\u53d8\u91cf\u53ef\u4ee5\u88ab\u6a21\u5757\u5185\u6240\u7528\u51fd\u6570\u8bbf\u95ee&#xff0c;\u4f46\u4e0d\u80fd\u88ab\u6a21\u5757\u5916\u5176\u5b83\u51fd\u6570\u8bbf\u95ee\u3002\u5b83\u662f\u4e00\u4e2a\u672c\u5730\u7684\u5168\u5c40\u53d8\u91cf&#xff08;\u53ea\u80fd\u88ab\u5f53\u524d\u6587\u4ef6\u4f7f\u7528&#xff09;\u3002<\/li>\n<li>\u5728\u6a21\u5757\u5185&#xff0c;\u4e00\u4e2a\u88ab\u58f0\u660e\u4e3a\u9759\u6001\u7684\u51fd\u6570\u53ea\u53ef\u88ab\u8fd9\u4e00\u6a21\u5757\u5185\u7684\u5176\u5b83\u51fd\u6570\u8c03\u7528\u3002\u90a3\u5c31\u662f&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u88ab\u9650\u5236\u5728\u58f0\u660e\u5b83\u7684\u6a21\u5757\u7684\u672c\u5730\u8303\u56f4\u5185\u4f7f\u7528&#xff08;\u53ea\u80fd\u88ab\u5f53\u524d\u6587\u4ef6\u4f7f\u7528&#xff09;\u3002<\/li>\n<h2>\u5728C\u8bed\u8a00\u4e2d&#xff0c;\u4e3a\u4ec0\u4e48static\u53d8\u91cf\u53ea\u521d\u59cb\u5316\u4e00\u6b21&#xff1f;<\/h2>\n<p>\u5bf9\u4e8e\u6240\u6709\u7684\u5bf9\u8c61&#xff08;\u4e0d\u4ec5\u4ec5\u662f\u9759\u6001\u5bf9\u8c61&#xff09;&#xff0c;\u521d\u59cb\u5316\u90fd\u53ea\u6709\u4e00\u6b21&#xff0c;\u800c\u7531\u4e8e\u9759\u6001\u53d8\u91cf\u5177\u6709\u201c\u8bb0\u5fc6\u201d\u529f\u80fd&#xff0c;\u521d\u59cb\u5316\u540e&#xff0c;\u4e00\u76f4\u90fd\u6ca1\u6709\u88ab\u9500\u6bc1&#xff0c;\u90fd\u4f1a\u4fdd\u5b58\u5728\u5185\u5b58\u533a\u57df\u4e2d&#xff0c;\u6240\u4ee5\u4e0d\u4f1a\u518d\u6b21\u521d\u59cb\u5316\u3002\u5b58\u653e\u5728\u9759\u6001\u533a\u7684\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u4e00\u822c\u6bd4\u8f83\u957f&#xff0c;\u5b83\u4e0e\u6574\u4e2a\u7a0b\u5e8f\u201c\u540c\u751f\u6b7b\u3001\u5171\u5b58\u4ea1\u201d&#xff0c;\u6240\u4ee5\u5b83\u53ea\u9700\u521d\u59cb\u5316\u4e00\u6b21\u3002\u800cauto\u53d8\u91cf&#xff0c;\u5373\u81ea\u52a8\u53d8\u91cf&#xff0c;\u7531\u4e8e\u5b83\u5b58\u653e\u5728\u6808\u533a&#xff0c;\u4e00\u65e6\u51fd\u6570\u8c03\u7528\u7ed3\u675f&#xff0c;\u5c31\u4f1a\u7acb\u523b\u88ab\u9500\u6bc1\u3002<\/p>\n<h2>extern \u201dC\u201c\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>extern &#034;C&#034;\u7684\u4e3b\u8981\u4f5c\u7528\u5c31\u662f\u4e3a\u4e86\u80fd\u591f\u6b63\u786e\u5b9e\u73b0C&#043;&#043;\u4ee3\u7801\u8c03\u7528\u5176\u4ed6C\u8bed\u8a00\u4ee3\u7801\u3002\u52a0\u4e0aextern &#034;C&#034;\u540e&#xff0c;\u4f1a\u6307\u793a\u7f16\u8bd1\u5668\u8fd9\u90e8\u5206\u4ee3\u7801\u6309C\u8bed\u8a00\u7684\u8fdb\u884c\u7f16\u8bd1&#xff0c;\u800c\u4e0d\u662fC&#043;&#043;\u7684\u3002<\/p>\n<h2>const\u6709\u4ec0\u4e48\u4f5c\u7528&#xff1f;<\/h2>\n<p>1.\u5b9a\u4e49\u53d8\u91cf&#xff08;\u5c40\u90e8\u53d8\u91cf\u6216\u5168\u5c40\u53d8\u91cf&#xff09;\u4e3a\u5e38\u91cf\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> N <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u5b9a\u4e49\u4e00\u4e2a\u5e38\u91cfN<\/span><br \/>\nN <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">50<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u9519\u8bef&#xff0c;\u5e38\u91cf\u7684\u503c\u4e0d\u80fd\u88ab\u4fee\u6539<\/span><br \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> n<span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u9519\u8bef&#xff0c;\u5e38\u91cf\u5728\u5b9a\u4e49\u7684\u65f6\u5019\u5fc5\u987b\u521d\u59cb\u5316<\/span><\/p>\n<p>2.\u4fee\u9970\u51fd\u6570\u7684\u53c2\u6570&#xff0c;\u8868\u793a\u5728\u51fd\u6570\u4f53\u5185\u4e0d\u80fd\u4fee\u6539\u8fd9\u4e2a\u53c2\u6570\u7684\u503c\u3002<\/p>\n<p>3.\u4fee\u9970\u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002<\/p>\n<ul>\n<li>a.\u5982\u679c\u7ed9\u7528 const\u4fee\u9970\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u4e3a\u6307\u9488&#xff0c;\u90a3\u4e48\u51fd\u6570\u8fd4\u56de\u503c&#xff08;\u5373\u6307\u9488&#xff09;\u7684\u5185\u5bb9\u662f\u4e0d\u80fd\u88ab\u4fee\u6539\u7684&#xff0c;\u800c\u4e14\u8fd9\u4e2a\u8fd4\u56de\u503c\u53ea\u80fd\u8d4b\u7ed9\u88abconst\u4fee\u9970\u7684\u6307\u9488\u3002\u4f8b\u5982<\/li>\n<\/ul>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span> <span class=\"token function\">GetString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<\/span><br \/>\n<span class=\"token keyword\">char<\/span> <span class=\"token operator\">*<\/span>str <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">GetString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u9519\u8bef&#xff0c;\u56e0\u4e3astr\u6ca1\u6709\u88abconst\u4fee\u9970<\/span><br \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span> <span class=\"token operator\">*<\/span>str <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">GetString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/\u6b63\u786e<\/span><\/p>\n<ul>\n<li>b.\u5982\u679c\u7528 const\u4fee\u9970\u666e\u901a\u7684\u8fd4\u56de\u503c&#xff0c;\u5982\u8fd4\u56deint\u53d8\u91cf&#xff0c;\u7531\u4e8e\u8fd9\u4e2a\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cf&#xff0c;\u5728\u51fd\u6570\u8c03\u7528\u7ed3\u675f\u540e\u8fd9\u4e2a\u4e34\u65f6\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u4e5f\u5c31\u7ed3\u675f\u4e86&#xff0c;\u56e0\u6b64\u628a\u8fd9\u4e9b\u8fd4\u56de\u503c\u4fee\u9970\u4e3a const\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002<\/li>\n<\/ul>\n<p>4.\u8282\u7701\u7a7a\u95f4&#xff0c;\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u5206\u914d\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">PI<\/span> <span class=\"token expression\"><span class=\"token number\">3.14159<\/span><\/span><span class=\"token comment\">\/\/\u8be5\u5b8f\u5728\u9884\u5904\u7406\u9636\u6bb5\u8fdb\u884c\u6587\u672c\u66ff\u6362&#xff0c;\u65e0\u5185\u5b58\u5206\u914d&#xff0c;\u4ec5\u4e3a\u5b57\u9762\u91cf\u66ff\u6362<\/span><\/span><br \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">double<\/span> pi <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">3.14159<\/span><span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/const\u4fee\u9970\u7684double\u7c7b\u578b\u5e38\u91cfpi&#xff0c;\u5b9a\u4e49\u65f6\u591a\u6570\u7f16\u8bd1\u5668\u4e0d\u4f1a\u7acb\u5373\u5206\u914d\u5185\u5b58&#xff08;\u672a\u653e\u5165\u53ea\u8bfb\u5b58\u50a8\u533a&#xff09;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> i <span class=\"token operator\">&#061;<\/span> pi<span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u9996\u6b21\u4f7f\u7528const\u53d8\u91cfpi&#xff0c;\u4e3a\u5176\u5206\u914d\u5185\u5b58&#xff08;\u901a\u5e38\u5728\u6570\u636e\u6bb5&#xff09;&#xff0c;\u540e\u7eed\u4f7f\u7528\u8be5\u5185\u5b58\u5730\u5740\u7684\u503c<\/span><br \/>\n<span class=\"token keyword\">double<\/span> I <span class=\"token operator\">&#061;<\/span> PI<span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u4f7f\u7528\u5b8fPI&#xff0c;\u7f16\u8bd1\u9884\u5904\u7406\u9636\u6bb5\u76f4\u63a5\u66ff\u6362\u4e3a3.14159&#xff0c;\u4e3aI\u5206\u914d\u5185\u5b58\u5b58\u50a8\u8be5\u5b57\u9762\u91cf\u503c<\/span><br \/>\n<span class=\"token keyword\">double<\/span> j <span class=\"token operator\">&#061;<\/span> pi<span class=\"token punctuation\">;<\/span><span class=\"token comment\">\/\/\u590d\u7528\u5df2\u5206\u914d\u5185\u5b58\u7684const\u53d8\u91cfPi&#xff0c;\u76f4\u63a5\u8bfb\u53d6\u5176\u5185\u5b58\u503c&#xff0c;\u65e0\u65b0\u5185\u5b58\u5206\u914d&#xff0c;\u4e5f\u65e0\u5b8f\u66ff\u6362<\/span><\/p>\n<h2>\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f7f\u7528const\u5173\u952e\u5b57&#xff1f;<\/h2>\n<p>1.\u4fee\u9970\u4e00\u822c\u53d8\u91cf\u3002\u4e00\u822c\u53d8\u91cf\u662f\u6307\u7b80\u5355\u7c7b\u578b\u7684\u5e38\u91cf\u3002\u8fd9\u79cd\u53d8\u91cf\u5728\u5b9a\u4e49\u65f6&#xff0c;\u4fee\u9970\u7b26const\u53ef\u4ee5\u7528\u5728\u7c7b\u578b\u8bf4\u660e\u7b26\u524d&#xff0c;\u4e5f\u53ef\u4ee5\u7528\u5728\u7c7b\u578b\u8bf4\u660e\u7b26\u540e\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token keyword\">const<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>2.\u4fee\u9970\u5e38\u6570\u7ec4\u3002\u5b9a\u4e49\u6216\u8bf4\u660e\u4e00\u4e2a\u5e38\u6570\u7ec4\u53ef\u4ee5\u91c7\u7528\u5982\u4e0b\u683c\u5f0f&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token keyword\">const<\/span> a<span class=\"token punctuation\">[<\/span><span class=\"token number\">8<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">6<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">7<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">8<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> a<span class=\"token punctuation\">[<\/span><span class=\"token number\">8<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">6<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">7<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">8<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>3.\u4fee\u9970\u5e38\u5bf9\u8c61\u3002\u5e38\u5bf9\u8c61\u662f\u6307\u5bf9\u8c61\u5e38\u91cf&#xff0c;\u5b9a\u4e49\u683c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<p>class A&#xff1a;<br \/>\n<span class=\"token keyword\">const<\/span> A a&#xff1a;<br \/>\nA <span class=\"token keyword\">const<\/span> a&#xff1a;<\/p>\n<p>\u5b9a\u4e49\u5e38\u5bf9\u8c61\u65f6&#xff0c;\u540c\u6837\u8981\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u5e76\u4e14\u8be5\u5bf9\u8c61\u4e0d\u80fd\u518d\u88ab\u66f4\u65b0\u3002\u4fee\u9970\u7b26 const\u53ef\u4ee5\u653e\u5728\u7c7b\u540d\u540e\u9762&#xff0c;\u4e5f\u53ef\u4ee5\u653e\u5728\u7c7b\u540d\u524d\u9762\u3002<\/p>\n<p>4.\u4fee\u9970\u5e38\u6307\u9488<\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span>p&#xff1b; <span class=\"token comment\">\/\/\u5e38\u91cf\u6307\u9488&#xff0c;\u6307\u5411\u5e38\u91cf\u7684\u6307\u9488\u3002\u5373p\u6307\u5411\u7684\u5185\u5b58\u53ef\u4ee5\u53d8&#xff0c;p\u6307\u5411\u7684\u6570\u503c\u5185\u5bb9\u4e0d\u53ef\u53d8<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token keyword\">const<\/span><span class=\"token operator\">*<\/span>p&#xff1b; <span class=\"token comment\">\/\/\u540c\u4e0a<\/span><br \/>\n<span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span><span class=\"token keyword\">const<\/span> p&#xff1b;<span class=\"token comment\">\/\/\u6307\u9488\u5e38\u91cf&#xff0c;\u672c\u8d28\u662f\u4e00\u4e2a\u5e38\u91cf&#xff0c;\u800c\u7528\u6307\u9488\u4fee\u9970\u5b83\u3002 \u5373p\u6307\u5411\u7684\u5185\u5b58\u4e0d\u53ef\u4ee5\u53d8&#xff0c;\u4f46\u662fp\u5185<\/span><br \/>\n\u5b58\u4f4d\u7f6e\u7684\u6570\u503c\u53ef\u4ee5\u53d8<br \/>\n<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> <span class=\"token keyword\">const<\/span> p&#xff1b;<span class=\"token comment\">\/\/\u6307\u5411\u5e38\u91cf\u7684\u5e38\u91cf\u6307\u9488\u3002\u5373p\u6307\u5411\u7684\u5185\u5b58\u548c\u6570\u503c\u90fd\u4e0d\u53ef\u53d8<\/span><\/p>\n<p>5.\u4fee\u9970\u5e38\u5f15\u7528\u3002\u88ab const\u4fee\u9970\u7684\u5f15\u7528\u53d8\u91cf\u4e3a\u5e38\u5f15\u7528&#xff0c;\u4e00\u65e6\u88ab\u521d\u59cb\u5316&#xff0c;\u5c31\u4e0d\u80fd\u518d\u6307\u5411\u5176\u4ed6\u5bf9\u8c61\u4e86\u3002<\/p>\n<p>6.\u4fee\u9970\u51fd\u6570\u7684\u5e38\u53c2\u6570\u3002 const\u4fee\u9970\u7b26\u4e5f\u53ef\u4ee5\u4fee\u9970\u51fd\u6570\u7684\u4f20\u9012\u53c2\u6570&#xff0c;\u683c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">void<\/span> Fun&#xff08;<span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> Var&#xff09;<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u544a\u8bc9\u7f16\u8bd1\u5668Var\u5728\u51fd\u6570\u4f53\u4e2d\u4e0d\u80fd\u88ab\u6539\u53d8&#xff0c;\u4ece\u800c\u9632\u6b62\u4e86\u4f7f\u7528\u8005\u4e00\u4e9b\u65e0\u610f\u7684\u6216\u9519\u8bef\u7684\u4fee\u6539\u3002<\/p>\n<p>7.\u4fee\u9970\u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002 const\u4fee\u9970\u7b26\u4e5f\u53ef\u4ee5\u4fee\u9970\u51fd\u6570\u7684\u8fd4\u56de\u503c&#xff0c;\u8868\u660e\u8be5\u8fd4\u56de\u503c\u4e0d\u53ef\u88ab\u6539\u53d8&#xff0c;\u683c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> FunI&#xff08;<span class=\"token punctuation\">)<\/span>&#xff1b;<br \/>\n<span class=\"token keyword\">const<\/span> MyClass Fun2&#xff08;&#xff09;&#xff1b;<\/p>\n<p>8.\u5728\u53e6\u4e00\u8fde\u63a5\u6587\u4ef6\u4e2d\u5f15\u7528 const\u5e38\u91cf\u3002\u4f7f\u7528\u65b9\u5f0f\u6709<\/p>\n<p><span class=\"token keyword\">extern<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">extern<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span> j<span class=\"token operator\">&#061;<\/span><span class=\"token number\">10<\/span>&#xff1b;<\/p>\n<h2>new\/delete\u4e0emalloc\/free\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>1.new\u3001delete\u662fC&#043;&#043;\u4e2d\u7684\u64cd\u4f5c\u7b26&#xff0c;\u800cmalloc\u548cfree\u662f\u6807\u51c6\u5e93\u51fd\u6570\u3002<\/p>\n<p>2.\u5bf9\u4e8e\u975e\u5185\u90e8\u6570\u636e\u5bf9\u8c61\u6765\u8bf4&#xff0c;\u53ea\u4f7f\u7528malloc\u662f\u65e0\u6cd5\u5b8c\u6210\u52a8\u6001\u5bf9\u8c61\u8981\u6c42\u7684&#xff0c;\u4e00\u822c\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u9700\u8981\u8c03\u7528\u6784\u9020\u51fd\u6570&#xff0c;\u5bf9\u8c61\u6d88\u4ea1\u65f6&#xff0c;\u81ea\u52a8\u7684\u8c03\u7528\u6790\u6784\u51fd\u6570\u3002\u800cmalloc free\u662f\u5e93\u51fd\u6570\u800c\u4e0d\u662f\u8fd0\u7b97\u7b26&#xff0c;\u4e0d\u5728\u7f16\u8bd1\u5668\u63a7\u5236\u8303\u56f4\u4e4b\u5185&#xff0c;\u4e0d\u80fd\u591f\u81ea\u52a8\u8c03\u7528\u6784\u9020\u51fd\u6570\u548c\u6790\u6784\u51fd\u6570\u3002\u800cNEW\u5728\u4e3a\u5bf9\u8c61\u7533\u8bf7\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u65f6&#xff0c;\u53ef\u4ee5\u81ea\u52a8\u8c03\u7528\u6784\u9020\u51fd\u6570&#xff0c;\u540c\u65f6\u4e5f\u53ef\u4ee5\u5b8c\u6210\u5bf9\u5bf9\u8c61\u7684\u521d\u59cb\u5316\u3002\u540c\u7406&#xff0c;delete\u4e5f\u53ef\u4ee5\u81ea\u52a8\u8c03\u7528\u6790\u6784\u51fd\u6570\u3002\u800cmallloc\u53ea\u662f\u505a\u4e00\u4ef6\u4e8b&#xff0c;\u53ea\u662f\u4e3a\u53d8\u91cf\u5206\u914d\u4e86\u5185\u5b58&#xff0c;\u540c\u7406&#xff0c;free\u4e5f\u53ea\u662f\u91ca\u653e\u53d8\u91cf\u7684\u5185\u5b58\u3002<\/p>\n<p>3.new\u8fd4\u56de\u7684\u662f\u6307\u5b9a\u7c7b\u578b\u7684\u6307\u9488&#xff0c;\u5e76\u4e14\u53ef\u4ee5\u81ea\u52a8\u8ba1\u7b97\u6240\u7533\u8bf7\u5185\u5b58\u7684\u5927\u5c0f\u3002\u800c malloc\u9700\u8981\u6211\u4eec\u8ba1\u7b97\u7533\u8bf7\u5185\u5b58\u7684\u5927\u5c0f&#xff0c;\u5e76\u4e14\u5728\u8fd4\u56de\u65f6\u5f3a\u884c\u8f6c\u6362\u4e3a\u5b9e\u9645\u7c7b\u578b\u7684\u6307\u9488\u3002<\/p>\n<h2>strlen(\u201c\\\\0\u201d) &#061; &#xff1f; sizeof(\u201c\\\\0\u201d) &#061; ?<\/h2>\n<p>strlen(\u201c\\\\0\u201d) &#061;0&#xff0c;sizeof(\u201c\\\\0\u201d)&#061;2\u3002 strlen\u7528\u6765\u8ba1\u7b97\u5b57\u7b26\u4e32\u7684\u957f\u5ea6&#xff08;\u5728C\/C&#043;&#043;\u4e2d&#xff0c;\u5b57\u7b26\u4e32\u662f\u4ee5&#034;\\\\0&#034;\u4f5c\u4e3a\u7ed3\u675f\u7b26\u7684&#xff09;&#xff0c;\u5b83\u4ece\u5185\u5b58\u7684\u67d0\u4e2a\u4f4d\u7f6e&#xff08;\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\u5f00\u5934&#xff0c;\u4e2d\u95f4\u67d0\u4e2a\u4f4d\u7f6e&#xff0c;\u751a\u81f3\u662f\u67d0\u4e2a\u4e0d\u786e\u5b9a\u7684\u5185\u5b58\u533a\u57df&#xff09;\u5f00\u59cb\u626b\u63cf\u76f4\u5230\u78b0\u5230\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7ed3\u675f\u7b26\\\\0\u4e3a\u6b62&#xff0c;\u7136\u540e\u8fd4\u56de\u8ba1\u6570\u5668\u503c&#xff1b;sizeof\u662fC\u8bed\u8a00\u7684\u5173\u952e\u5b57&#xff0c;\u5b83\u4ee5\u5b57\u8282\u7684\u5f62\u5f0f\u7ed9\u51fa\u4e86\u5176\u64cd\u4f5c\u6570\u7684\u5b58\u50a8\u5927\u5c0f&#xff0c;\u64cd\u4f5c\u6570\u53ef\u4ee5\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\u6216\u62ec\u5728\u62ec\u53f7\u5185\u7684\u7c7b\u578b\u540d&#xff0c;\u64cd\u4f5c\u6570\u7684\u5b58\u50a8\u5927\u5c0f\u7531\u64cd\u4f5c\u6570\u7684\u7c7b\u578b\u51b3\u5b9a\u3002<\/p>\n<h2>sizeof\u4e0estrlen\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;<\/h2>\n<p>strlen\u4e0e sizeof\u7684\u5dee\u522b\u8868\u73b0\u5728\u4ee5\u4e0b5\u4e2a\u65b9\u9762\u3002<\/p>\n<li>\n<p>sizeof\u662f\u8fd0\u7b97\u7b26&#xff08;sizeof\u65e2\u662f\u5173\u952e\u5b57&#xff0c;\u4e5f\u662f\u8fd0\u7b97\u7b26&#xff0c;\u4f46\u4e0d\u662f\u51fd\u6570&#xff09;&#xff0c;\u800cstrlen\u662f\u51fd\u6570\u3002 sizeof\u540e\u5982\u679c\u662f\u7c7b\u578b&#xff0c;\u5219\u5fc5\u987b\u52a0\u62ec\u5f27&#xff0c;\u5982\u679c\u662f\u53d8\u91cf\u540d&#xff0c;\u5219\u53ef\u4ee5\u4e0d\u52a0\u62ec\u5f27\u3002<\/p>\n<\/li>\n<li>\n<p>sizeof\u8fd0\u7b97\u7b26\u7684\u7ed3\u679c\u7c7b\u578b\u662f size_t&#xff0c;\u5b83\u5728\u5934\u6587\u4ef6\u4e2d typedef\u4e3a unsigned int\u7c7b\u578b\u3002\u8be5\u7c7b\u578b\u4fdd\u8bc1\u80fd\u591f \u5bb9\u7eb3\u5b9e\u73b0\u6240\u5efa\u7acb\u7684\u6700\u5927\u5bf9\u8c61\u7684\u5b57\u8282\u5927\u5c0f\u3002<\/p>\n<\/li>\n<li>\n<p>sizeof\u53ef\u4ee5\u7528\u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570&#xff0c; strlen\u53ea\u80fd\u7528char*\u4f5c\u53c2\u6570&#xff0c;\u800c\u4e14\u5fc5\u987b\u662f\u4ee5\u201c0\u7ed3\u5c3e\u7684\u3002 sizeof\u8fd8\u53ef\u4ee5\u4ee5\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u5982int g&#xff08;&#xff09;&#xff0c;\u5219 sizeof&#xff08;g&#xff08;&#xff09;&#xff09;\u7684\u503c\u7b49\u4e8e sizeof&#xff08; int\u7684\u503c&#xff0c;\u572832\u4f4d\u8ba1\u7b97\u673a\u4e0b&#xff0c;\u8be5\u503c\u4e3a4\u3002<\/p>\n<\/li>\n<li>\n<p>\u5927\u90e8\u5206\u7f16\u8bd1\u7a0b\u5e8f\u7684 sizeof\u90fd\u662f\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u8ba1\u7b97\u7684&#xff0c;\u6240\u4ee5\u53ef\u4ee5\u901a\u8fc7 sizeof&#xff08;x&#xff09;\u6765\u5b9a\u4e49\u6570\u7ec4\u7ef4\u6570\u3002\u800c strlen\u5219\u662f\u5728\u8fd0\u884c\u671f\u8ba1\u7b97\u7684&#xff0c;\u7528\u6765\u8ba1\u7b97\u5b57\u7b26\u4e32\u7684\u5b9e\u9645\u957f\u5ea6&#xff0c;\u4e0d\u662f\u7c7b\u578b\u5360\u5185\u5b58\u7684\u5927\u5c0f\u3002\u4f8b\u5982&#xff0c; char str[20] &#061; &#034;0123456789\u201d&#xff0c;\u5b57\u7b26\u6570\u7ec4str\u662f\u7f16\u8bd1\u671f\u5927\u5c0f\u5df2\u7ecf\u56fa\u5b9a\u7684\u6570\u7ec4&#xff0c;\u572832\u4f4d\u673a\u5668\u4e0b&#xff0c;\u4e3asizeof&#xff08;char&#xff09;*20&#061;20&#xff0c;\u800c\u5176 strlen\u5927\u5c0f\u5219\u662f\u5728\u8fd0\u884c\u671f\u786e\u5b9a\u7684&#xff0c;\u6240\u4ee5\u5176\u503c\u4e3a\u5b57\u7b26\u4e32\u7684\u5b9e\u9645\u957f\u5ea610\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u51fd\u6570\u65f6&#xff0c;\u4f20\u9012\u7684\u662f\u6307\u9488&#xff0c;\u800c\u4e0d\u662f\u6570\u7ec4&#xff0c;\u5373\u4f20\u9012\u7684\u662f\u6570\u7ec4\u7684\u9996\u5730\u5740\u3002<\/p>\n<\/li>\n<h2>\u4e0d\u4f7f\u7528sizeof&#xff0c;\u5982\u4f55\u6c42int\u5360\u7528\u7684\u5b57\u8282\u6570&#xff1f;<\/h2>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">MySizeof<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>value<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">char<\/span> <span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>value<span class=\"token operator\">&#043;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&#8211;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&amp;<\/span>value<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">int<\/span> i<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> f<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> a<span class=\"token punctuation\">[<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> <span class=\"token operator\">*<\/span>q<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;%d\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token function\">MySizeof<\/span><span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;%d\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token function\">MySizeof<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;%d\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token function\">MySizeof<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;%d\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token function\">MySizeof<\/span><span class=\"token punctuation\">(<\/span>q<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8f93\u51fa\u4e3a&#xff1a;<\/p>\n<p>Output: 4 8 32 4<\/p>\n<p>\u4e0a\u4f8b\u4e2d&#xff0c;(char*)&amp; Value \u8fd4\u56de Value\u7684\u5730\u5740\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282&#xff0c;(char*)(&amp; Value&#043;1)\u8fd4\u56devalue\u7684\u5730\u5740\u7684\u4e0b\u4e00\u4e2a\u5730\u5740\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282&#xff0c;\u6240\u4ee5\u5b83\u4eec\u4e4b\u5dee\u4e3a\u5b83\u6240\u5360\u7684\u5b57\u8282\u6570\u3002<\/p>\n<h2>C\u8bed\u8a00\u4e2dstruct\u4e0eunion\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>struct&#xff08;\u7ed3\u6784\u4f53&#xff09;\u4e0e union&#xff08;\u8054\u5408\u4f53&#xff09;\u662fC\u8bed\u8a00\u4e2d\u4e24\u79cd\u4e0d\u540c\u7684\u6570\u636e\u7ed3\u6784&#xff0c;\u4e24\u8005\u90fd\u662f\u5e38\u89c1\u7684\u590d\u5408\u7ed3\u6784&#xff0c;\u5176\u533a\u522b\u4e3b\u8981\u8868\u73b0\u5728\u4ee5\u4e0b\u4e24\u4e2a\u65b9\u9762\u3002<\/p>\n<li>\u7ed3\u6784\u4f53\u4e0e\u8054\u5408\u4f53\u867d\u7136\u90fd\u662f\u7531\u591a\u4e2a\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u6210\u5458\u7ec4\u6210\u7684&#xff0c;\u4f46\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\u8054\u5408\u4f53\u4e2d\u6240\u6709\u6210\u5458\u5171\u7528\u4e00\u5757\u5730\u5740\u7a7a\u95f4&#xff0c;\u5373\u8054\u5408\u4f53\u53ea\u5b58\u653e\u4e86\u4e00\u4e2a\u88ab\u9009\u4e2d\u7684\u6210\u5458&#xff0c;\u800c\u7ed3\u6784\u4f53\u4e2d\u6240\u6709\u6210\u5458\u5360\u7528\u7a7a\u95f4\u662f\u7d2f\u52a0\u7684&#xff0c;\u5176\u6240\u6709\u6210\u5458\u90fd\u5b58\u5728&#xff0c;\u4e0d\u540c\u6210\u5458\u4f1a\u5b58\u653e\u5728\u4e0d\u540c\u7684\u5730\u5740\u3002\u5728\u8ba1\u7b97\u4e00\u4e2a\u7ed3\u6784\u578b\u53d8\u91cf\u7684\u603b\u957f\u5ea6\u65f6&#xff0c;\u5176\u5185\u5b58\u7a7a\u95f4\u5927\u5c0f\u7b49\u4e8e\u6240\u6709\u6210\u5458\u957f\u5ea6\u4e4b\u548c&#xff08;\u9700\u8981\u8003\u8651\u5b57\u8282\u5bf9\u9f50&#xff09;&#xff0c;\u800c\u5728\u8054\u5408\u4f53\u4e2d&#xff0c;\u6240\u6709\u6210\u5458\u4e0d\u80fd\u540c\u65f6\u5360\u7528\u5185\u5b58\u7a7a\u95f4&#xff0c;\u5b83\u4eec\u4e0d\u80fd\u540c\u65f6\u5b58\u5728&#xff0c;\u6240\u4ee5\u4e00\u4e2a\u8054\u5408\u578b\u53d8\u91cf\u7684\u957f\u5ea6\u7b49\u4e8e\u5176\u6700\u957f\u7684\u6210\u5458\u7684\u957f\u5ea6\u3002<\/li>\n<li>\u5bf9\u4e8e\u8054\u5408\u4f53\u7684\u4e0d\u540c\u6210\u5458\u8d4b\u503c&#xff0c;\u5c06\u4f1a\u5bf9\u5b83\u7684\u5176\u4ed6\u6210\u5458\u91cd\u5199&#xff0c;\u539f\u6765\u6210\u5458\u7684\u503c\u5c31\u4e0d\u5b58\u5728\u4e86&#xff0c;\u800c\u5bf9\u7ed3\u6784\u4f53\u7684\u4e0d\u540c\u6210\u5458\u8d4b\u503c\u662f\u4e92\u4e0d\u5f71\u54cd\u7684\u3002<\/li>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\u3002\u4e0b\u5217\u4ee3\u7801\u6267\u884c\u7ed3\u679c\u662f\u591a\u5c11&#xff1f;<\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">union<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token keyword\">double<\/span> i<span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">int<\/span> k<span class=\"token punctuation\">[<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">char<\/span> c<span class=\"token punctuation\">;<\/span><span class=\"token punctuation\">}<\/span>DATE<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">data<\/span><span class=\"token punctuation\">(<\/span> <span class=\"token keyword\">int<\/span> cat<span class=\"token punctuation\">;<\/span> DATE cow<span class=\"token punctuation\">;<\/span><span class=\"token keyword\">double<\/span> dog<span class=\"token punctuation\">;<\/span>&#xff09;too<span class=\"token punctuation\">;<\/span><\/p>\n<p>DATE max<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token function\">printf<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;%d&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>too<span class=\"token punctuation\">)<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>max<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5047\u8bbe\u4e3a32\u4f4d\u673a\u5668&#xff0c;int\u578b\u53604\u4e2a\u5b57\u8282&#xff0c; double\u578b\u53608\u4e2a\u5b57\u8282&#xff0c;char\u578b\u53601\u4e2a\u5b57\u8282&#xff0c;\u800cDATE\u662f\u4e00\u4e2a\u8054\u5408\u578b\u53d8\u91cf&#xff0c;\u8054\u5408\u578b\u53d8\u91cf\u5171\u7528\u7a7a\u95f4&#xff0c;uion\u91cc\u9762\u6700\u5927\u7684\u53d8\u91cf\u7c7b\u578b\u662fint[5]&#xff0c;\u6240\u4ee5\u5360\u752820\u4e2a\u5b57\u8282&#xff0c;\u5b83\u7684\u5927\u5c0f\u662f20&#xff0c;\u800c\u7531\u4e8e union\u4e2d double\u5360\u4e868\u4e2a\u5b57\u8282&#xff0c;\u56e0\u6b64 union\u662f\u89818\u4e2a\u5b57\u8282\u5bf9\u9f50&#xff0c;\u6240\u5360\u5185\u5b58\u7a7a\u95f4\u4e3a8\u7684\u500d\u6570\u3002\u4e3a\u4e86\u5b9e\u73b08\u4e2a\u5b57\u8282\u5bf9\u9f50&#xff0c;\u6240\u5360\u7a7a\u95f4\u4e3a24\u3002\u800cdata\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf&#xff0c;\u6bcf\u4e2a\u53d8\u91cf\u5206\u5f00\u5360\u7528\u7a7a\u95f4&#xff0c;\u4f9d\u6b21\u4e3a sizeof(int) &#043; sizeof(DATE) &#043; sizeof(double) &#061; 4 &#043; 24 &#043; 8 &#061; 36&#xff0c;\u6309\u71678\u5b57\u8282\u5bf9\u9f50&#xff0c;\u5360\u7528\u7a7a\u95f4\u4e3a40&#xff0c;\u6240\u4ee5\u7ed3\u679c\u4e3a40&#043;24&#061;64\u3002<\/p>\n<h2>\u5de6\u503c\u548c\u53f3\u503c\u662f\u4ec0\u4e48&#xff1f;<\/h2>\n<p>\u5de6\u503c\u662f\u6307\u53ef\u4ee5\u51fa\u73b0\u5728\u7b49\u53f7\u5de6\u8fb9\u7684\u53d8\u91cf\u6216\u8868\u8fbe\u5f0f&#xff0c;\u5b83\u6700\u91cd\u8981\u7684\u7279\u70b9\u5c31\u662f\u53ef\u5199&#xff08;\u53ef\u5bfb\u5740&#xff09;\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u5b83\u7684\u503c\u53ef\u4ee5\u88ab\u4fee\u6539&#xff0c;\u5982\u679c\u4e00\u4e2a\u53d8\u91cf\u6216\u8868\u8fbe\u5f0f\u7684\u503c\u4e0d\u80fd\u88ab\u4fee\u6539&#xff0c;\u90a3\u4e48\u5b83\u5c31\u4e0d\u80fd\u4f5c\u4e3a\u5de6\u503c\u3002<\/p>\n<p>\u53f3\u503c\u662f\u6307\u53ea\u53ef\u4ee5\u51fa\u73b0\u5728\u7b49\u53f7\u53f3\u8fb9\u7684\u53d8\u91cf\u6216\u8868\u8fbe\u5f0f\u3002\u5b83\u6700\u91cd\u8981\u7684\u7279\u70b9\u662f\u53ef\u8bfb\u3002\u4e00\u822c\u7684\u4f7f\u7528\u573a\u666f\u90fd\u662f\u628a\u4e00\u4e2a\u53f3\u503c\u8d4b\u503c\u7ed9\u4e00\u4e2a\u5de6\u503c\u3002<\/p>\n<p>\u901a\u5e38&#xff0c;\u5de6\u503c\u53ef\u4ee5\u4f5c\u4e3a\u53f3\u503c&#xff0c;\u4f46\u662f\u53f3\u503c\u4e0d\u4e00\u5b9a\u662f\u5de6\u503c\u3002<\/p>\n<h2>\u4ec0\u4e48\u662f\u77ed\u8def\u6c42\u503c&#xff1f;<\/h2>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">6<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> j <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>i<span class=\"token operator\">&gt;<\/span><span class=\"token number\">0<\/span><span class=\"token operator\">||<\/span><span class=\"token punctuation\">(<\/span>j<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;%D\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span>j<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\u4e3a1\u3002<\/p>\n<p>\u8f93\u51fa\u4e3a\u4ec0\u4e48\u4e0d\u662f2&#xff0c;\u800c\u662f1\u5462&#xff1f;\u8fd9\u91cc\u5c31\u6d89\u53ca\u4e00\u4e2a\u77ed\u8def\u8ba1\u7b97\u7684\u95ee\u9898\u3002\u7531\u4e8e if \u8bed\u53e5\u662f\u4e2a\u6761\u4ef6\u5224\u65ad\u8bed\u53e5&#xff0c;\u91cc\u9762\u662f\u6709\u4e24\u4e2a\u7b80\u5355\u8bed\u53e5\u8fdb\u884c\u6216\u8fd0\u7b97\u7ec4\u5408\u7684\u590d\u5408\u8bed\u53e5&#xff0c;\u56e0\u4e3a\u6216\u8fd0\u7b97\u4e2d&#xff0c;\u53ea\u8981\u53c2\u4e0e\u6216\u8fd0\u7b97\u7684\u4efb\u610f\u8868\u8fbe\u5f0f\u7684\u503c\u4e3a\u771f&#xff0c;\u5219\u6574\u4e2a\u8fd0\u7b97\u7ed3\u679c\u4e3a\u771f\u3002\u800c\u7531\u4e8e\u53d8\u91cfi\u7684\u503c\u4e3a6&#xff0c;\u5df2\u7ecf\u5927\u4e8e0\u4e86&#xff0c;\u800c\u8be5\u8bed\u53e5\u5df2\u7ecf\u4e3atrue&#xff0c;\u5219\u4e0d\u9700\u8981\u6267\u884c\u540e\u7eed\u7684 j&#043;&#043; \u64cd\u4f5c\u6765\u5224\u65ad\u771f\u5047&#xff0c;\u6240\u4ee5\u540e\u7eed\u7684 j&#043;&#043; \u64cd\u4f5c\u4e0d\u9700\u8981\u6267\u884c&#xff0c;j \u7684\u503c\u4ecd\u7136\u4e3a1\u3002<\/p>\n<p>\u56e0\u4e3a\u77ed\u8def\u8ba1\u7b97\u7684\u95ee\u9898&#xff0c;\u5bf9\u4e8e&amp;&amp;\u64cd\u4f5c&#xff0c;\u7531\u4e8e\u5728\u4e24\u4e2a\u8868\u8fbe\u5f0f\u7684\u8fd4\u56de\u503c\u4e2d&#xff0c;\u5982\u679c\u6709\u4e00\u4e2a\u4e3a\u5047\u5219\u6574\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\u90fd\u4e3a\u5047\u3002\u5982\u679c\u524d\u4e00\u4e2a\u8bed\u53e5\u7684\u8fd4\u56de\u503c\u4e3a false&#xff0c;\u5219\u65e0\u8bba\u540e\u4e00\u4e2a\u8bed\u53e5\u7684\u8fd4\u56de\u503c\u662f\u771f\u662f\u5047&#xff0c;\u6574\u4e2a\u6761\u4ef6\u5224\u65ad\u90fd\u4e3a\u5047&#xff0c;\u4e0d\u7528\u6267\u884c\u540e\u4e00\u4e2a\u8bed\u53e5\u3002<\/p>\n<h2>&#043;&#043;a\u548ca&#043;&#043;\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;\u4e24\u8005\u662f\u5982\u4f55\u5b9e\u73b0\u7684&#xff1f;<\/h2>\n<p>a&#043;&#043;\u7684\u5177\u4f53\u8fd0\u7b97\u8fc7\u7a0b\u4e3a&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> temp <span class=\"token operator\">&#061;<\/span> a<span class=\"token punctuation\">;<\/span><br \/>\na <span class=\"token operator\">&#061;<\/span> a <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> temp<span class=\"token punctuation\">;<\/span><\/p>\n<p>&#043;&#043;a\u7684\u5177\u4f53\u8fd0\u7b97\u8fc7\u7a0b\u4e3a&#xff1a;<\/p>\n<p>a <span class=\"token operator\">&#061;<\/span> a <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> a<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u540e\u7f6e\u81ea\u589e\u8fd0\u7b97\u7b26\u9700\u8981\u628a\u539f\u6765\u53d8\u91cf\u7684\u503c\u590d\u5236\u5230\u4e00\u4e2a\u4e34\u65f6\u7684\u5b58\u50a8\u7a7a\u95f4&#xff0c;\u7b49\u8fd0\u7b97\u7ed3\u675f\u540e\u624d\u4f1a\u8fd4\u56de\u8fd9\u4e2a\u4e34\u65f6\u53d8\u91cf\u7684\u503c\u3002\u6240\u4ee5\u524d\u7f6e\u81ea\u589e\u8fd0\u7b97\u7b26\u6548\u7387\u6bd4\u540e\u7f6e\u81ea\u589e\u8981\u9ad8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u952e\u5b57C\u8bed\u8a00\u5b8f\u4e2d\u201c#\u201d\u548c\u201c##\u201d\u7684\u7528\u6cd5\u5173\u952e\u5b57volatile\u6709\u4ec0\u4e48\u542b\u4e49&#xff1f;\u5e76\u4e3e\u51fa\u4e09\u4e2a\u4e0d\u540c\u7684\u4f8b\u5b50&#xff1f;\u5173\u952e\u5b57static\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;\u5728C\u8bed\u8a00\u4e2d&#xff0c;\u4e3a\u4ec0\u4e48static\u53d8\u91cf\u53ea\u521d\u59cb\u5316\u4e00\u6b21&#xff1f;extern \u201dC\u201c\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;const\u6709\u4ec0\u4e48\u4f5c\u7528&#xff1f;\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f7f\u7528const\u5173\u952e\u5b57&#xff1f;new\/delete\u4e0emalloc\/free\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;strlen(\\&#8221;\\\\0\\&#8221;)  &amp;#x<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,174,371],"topic":[],"class_list":{"0":"post-76580","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-c","9":"tag-371"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\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\/76580.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5173\u952e\u5b57C\u8bed\u8a00\u5b8f\u4e2d\u201c#\u201d\u548c\u201c##\u201d\u7684\u7528\u6cd5\u5173\u952e\u5b57volatile\u6709\u4ec0\u4e48\u542b\u4e49&#xff1f;\u5e76\u4e3e\u51fa\u4e09\u4e2a\u4e0d\u540c\u7684\u4f8b\u5b50&#xff1f;\u5173\u952e\u5b57static\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;\u5728C\u8bed\u8a00\u4e2d&#xff0c;\u4e3a\u4ec0\u4e48static\u53d8\u91cf\u53ea\u521d\u59cb\u5316\u4e00\u6b21&#xff1f;extern \u201dC\u201c\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;const\u6709\u4ec0\u4e48\u4f5c\u7528&#xff1f;\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f7f\u7528const\u5173\u952e\u5b57&#xff1f;new\/delete\u4e0emalloc\/free\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;strlen(&quot;\\0&quot;) &amp;#x\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/76580.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-22T13:09:25+00:00\" \/>\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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76580.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/76580.html\",\"name\":\"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-22T13:09:25+00:00\",\"dateModified\":\"2026-02-22T13:09:25+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/76580.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/76580.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76580.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\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":"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\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\/76580.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5173\u952e\u5b57C\u8bed\u8a00\u5b8f\u4e2d\u201c#\u201d\u548c\u201c##\u201d\u7684\u7528\u6cd5\u5173\u952e\u5b57volatile\u6709\u4ec0\u4e48\u542b\u4e49&#xff1f;\u5e76\u4e3e\u51fa\u4e09\u4e2a\u4e0d\u540c\u7684\u4f8b\u5b50&#xff1f;\u5173\u952e\u5b57static\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;\u5728C\u8bed\u8a00\u4e2d&#xff0c;\u4e3a\u4ec0\u4e48static\u53d8\u91cf\u53ea\u521d\u59cb\u5316\u4e00\u6b21&#xff1f;extern \u201dC\u201c\u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;const\u6709\u4ec0\u4e48\u4f5c\u7528&#xff1f;\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f7f\u7528const\u5173\u952e\u5b57&#xff1f;new\/delete\u4e0emalloc\/free\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;strlen(\"\\0\") &amp;#x","og_url":"https:\/\/www.wsisp.com\/helps\/76580.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-22T13:09:25+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/76580.html","url":"https:\/\/www.wsisp.com\/helps\/76580.html","name":"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-22T13:09:25+00:00","dateModified":"2026-02-22T13:09:25+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/76580.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/76580.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/76580.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5d4c\u5165\u5f0f\u77e5\u8bc6\u70b9\u5b66\u4e60\u7bc7\u4e00\uff08C\/C++\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\/76580","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=76580"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76580\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=76580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=76580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=76580"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=76580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}