{"id":73398,"date":"2026-02-07T15:36:01","date_gmt":"2026-02-07T07:36:01","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/73398.html"},"modified":"2026-02-07T15:36:01","modified_gmt":"2026-02-07T07:36:01","slug":"c%e5%9f%ba%e7%a1%80%ef%bc%9astanford-cs106l%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0-5-%e5%86%85%e5%ad%98%e4%b8%8e%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/73398.html","title":{"rendered":"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488"},"content":{"rendered":"<\/p>\n<h4>\u76ee\u5f55<\/h4>\n<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li>5.1 \u5185\u5b58<\/li>\n<li>\n<ul>\n<li>5.1.1 \u6808<\/li>\n<li>\n<ul>\n<li>**\u6808\u7684\u5b58\u50a8**<\/li>\n<li>**\u6808\u6ea2\u51fa**<\/li>\n<li>**\u6808\u7684\u5c40\u9650**<\/li>\n<\/ul>\n<\/li>\n<li>5.1.2 \u5806<\/li>\n<\/ul>\n<\/li>\n<li>5.2 \u6307\u9488<\/li>\n<li>\n<ul>\n<li>5.2.1 \u6307\u9488\u7c7b\u578b<\/li>\n<li>\n<ul>\n<li>\\\\*\u89e3\u5f15\u7528<\/li>\n<li>-&gt;\u89e3\u5f15\u7528\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458<\/li>\n<li>const\u4e0e\u6307\u9488<\/li>\n<li>&#096;nullptr&#096;<\/li>\n<\/ul>\n<\/li>\n<li>5.2.2 \u6307\u5411\u5806\u7684\u6307\u9488<\/li>\n<li>\n<ul>\n<li>&#096;new&#096;<\/li>\n<li>&#096;delete&#096;<\/li>\n<li>&#096;new[]&#096; \u548c &#096;delete[]&#096;<\/li>\n<\/ul>\n<\/li>\n<li>5.2.3 \u6307\u9488\u8fd0\u7b97<\/li>\n<li>5.2.4 \u4e0e\u5f15\u7528\u7684\u5173\u7cfb<\/li>\n<li>5.2.5 \u7efc\u5408\u5e94\u7528<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>5.1 \u5185\u5b58<\/h4>\n<p>\u5728\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00\u4e2d&#xff0c;\u4f60\u521b\u5efa\u7684\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5b58\u5728\u4e8e\u7a0b\u5e8f\u5185\u5b58\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002\u5f53\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\u65f6&#xff0c;\u5b83\u4f1a\u7ed9\u6bcf\u4e2a\u7a0b\u5e8f&#xff08;\u66f4\u5177\u4f53\u5730\u8bf4&#xff0c;\u6bcf\u4e2a\u8fdb\u7a0b&#xff09;\u5206\u914d\u4e00\u5b9a\u91cf\u7684\u5185\u5b58\u4f9b\u5176\u4f7f\u7528&#xff0c;\u8fd9\u88ab\u79f0\u4e3a\u8be5\u7a0b\u5e8f\u7684\u5730\u5740\u7a7a\u95f4\u3002\u4ece\u6982\u5ff5\u4e0a\u8bb2&#xff0c;\u5730\u5740\u7a7a\u95f4\u53ef\u4ee5\u88ab\u89c6\u4e3a\u4e00\u5927\u5757\u4e8c\u8fdb\u5236\u6570\u636e&#xff1a;\u7531 0 \u548c 1 \u7ec4\u6210\u3002\u7136\u800c&#xff0c;\u5728\u5b9e\u9645\u4e2d&#xff0c;\u8fd9\u5757\u6570\u636e\u88ab\u5212\u5206\u4e3a\u4e0d\u540c\u7684\u90e8\u5206&#xff1a;<\/p>\n<table>\n<tr>\u5730\u533a\u63cf\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>\u5171\u4eab\u5185\u5b58<\/td>\n<td>\u64cd\u4f5c\u7cfb\u7edf\u9884\u7559\u7684\u3001\u4e0e\u7a0b\u5e8f\u5171\u4eab\u7684\u5185\u5b58&#xff0c;\u5b83\u5141\u8bb8\u5f53\u524d\u8fdb\u7a0b\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u548c\/\u6216\u5176\u4ed6\u8fdb\u7a0b\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1<\/td>\n<\/tr>\n<tr>\n<td>\u6808<\/td>\n<td>\u5b58\u50a8\u200b\u51fd\u6570\u8c03\u7528\u200b\u3001\u5c40\u90e8\u53d8\u91cf\u548c\u63a7\u5236\u6d41\u4fe1\u606f&#xff0c;\u4f1a\u968f\u7740\u51fd\u6570\u7684\u6267\u884c\u81ea\u52a8\u589e\u5927\u548c\u7f29\u5c0f&#xff08;\u5982\u4e0b\u6240\u8ff0&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5806<\/td>\n<td>\u5b58\u50a8\u200b\u52a8\u6001\u5206\u914d\u7684\u5bf9\u8c61\u200b&#xff0c;\u8fd9\u4e9b\u5bf9\u8c61\u7684\u5b58\u5728\u65f6\u95f4\u8d85\u8fc7\u51fd\u6570\u8c03\u7528&#xff0c;\u5e76\u4e14\u9700\u8981\u7a0b\u5e8f\u5458\u8fdb\u884c\u663e\u5f0f\u7ba1\u7406&#xff08;\u5982\u4e0b\u6240\u8ff0&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5168\u5c40\u53d8\u91cf<\/td>\n<td>\u5728\u51fd\u6570\u5916\u90e8\u58f0\u660e\u7684\u53d8\u91cf\u5b58\u653e\u5728\u8fd9\u91cc<\/td>\n<\/tr>\n<tr>\n<td>\u6307\u4ee4\u6bb5<\/td>\n<td>\u4e5f\u79f0\u4e3a\u200b\u6587\u672c\u6bb5\u200b\u3002\u8fd9\u91cc\u5b58\u653e\u7684\u662f\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u8fdb\u7a0b\u4ee3\u7801&#xff1a;\u7f16\u8bd1\u5668\u751f\u6210\u7684\u539f\u59cb\u673a\u5668\u7801\u5c31\u4f4d\u4e8e\u6b64\u5904<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5e22aba.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5185\u5b58\u901a\u5e38\u662f\u6309\u5b57\u8282\u5bfb\u5740\u7684&#xff0c;\u6bcf\u4e2a\u5b57\u8282\u4ece 0 \u5f00\u59cb\u7f16\u53f7\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5e4ae72.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6bcf\u4e2a\u533a\u57df\u90fd\u6709\u91cd\u8981\u7684\u7528\u9014&#xff0c;\u4f46\u5728\u6211\u4eec\u5173\u4e8e C&#043;&#043; \u7684\u8ba8\u8bba\u4e2d&#xff0c;\u6211\u4eec\u5c06\u91cd\u70b9\u5173\u6ce8\u6808\u548c\u200b\u5806\u200b&#xff0c;\u56e0\u4e3a\u8fd9\u4e24\u4e2a\u5730\u65b9\u662f\u7a0b\u5e8f\u53d8\u91cf\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002<\/p>\n<h5>5.1.1 \u6808<\/h5>\n<p>\u200b\u6808\u200b&#xff08;\u4e5f\u79f0\u4e3a\u8c03\u7528\u6808\u6216\u200b\u7a0b\u5e8f\u6808\u200b&#xff09;\u662f\u5b58\u50a8\u51fd\u6570\u8c03\u7528\u53ca\u5176\u5c40\u90e8\u53d8\u91cf\u7684\u5730\u65b9\u3002\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6&#xff0c;\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u200b\u6808\u5e27\u200b&#xff08;\u4e5f\u79f0\u4e3a\u200b\u6d3b\u52a8\u8bb0\u5f55\u200b&#xff09;\u6765\u5b58\u50a8\u8be5\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<p>\u6808\u5148\u8fdb\u540e\u51fa\u3002<\/p>\n<h6>\u6808\u7684\u5b58\u50a8<\/h6>\n<p>\u7531\u4e8emain\u662f\u4efb\u4f55 C&#043;&#043; \u7a0b\u5e8f\u8c03\u7528\u7684\u7b2c\u4e00\u4e2a\u51fd\u6570&#xff0c;\u56e0\u6b64\u5728\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4&#xff0c;\u603b\u4f1a\u6709\u4e00\u4e2amain\u51fd\u6570\u4f4d\u4e8e\u6808\u7684\u5e95\u90e8&#xff08;\u53ea\u6709\u5f53\u7a0b\u5e8f\u9000\u51fa\u65f6\u624d\u4f1a\u88ab\u5f39\u51fa&#xff09;\u3002\u5f53\u8c03\u7528\u5176\u4ed6\u51fd\u6570\u65f6&#xff0c;\u5b83\u4eec\u7684\u6808\u5e27\u4f1a\u88ab\u538b\u5165\u5230\u524d\u4e00\u4e2a\u6808\u5e27\u7684\u9876\u90e8\u3002\u53ef\u4ee5\u4f7f\u7528\u6808\u56fe\u6765\u63cf\u7ed8\u7a0b\u5e8f\u751f\u547d\u5468\u671f\u4e2d\u4efb\u610f\u65f6\u523b\u7684\u8fd9\u4e00\u8fc7\u7a0b\u3002\u7531\u4e8e\u6808\u5728\u5185\u5b58\u4e2d\u5b9e\u9645\u4e0a\u662f\u5411\u4e0b\u589e\u957f\u7684&#xff08;\u540e\u9762\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e00\u70b9&#xff09;&#xff0c;\u6240\u4ee5\u5728\u7ed8\u5236\u6808\u56fe\u65f6&#xff0c;\u901a\u5e38\u4f1a\u5c06main\u51fd\u6570\u653e\u5728\u9876\u90e8&#xff0c;\u5176\u4ed6\u51fd\u6570\u653e\u5728\u5176\u4e0b\u65b9\u3002\u4f8b\u5982&#xff1a;<\/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> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token function\">foo<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">106<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">107<\/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><span class=\"token keyword\">void<\/span> <span class=\"token function\">foo<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> z<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">int<\/span> y <span class=\"token operator\">&#061;<\/span> z<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u884c1&#xff1a;\u6b64\u65f6&#xff0c;\u5b58\u5728\u4e00\u4e2a\u5355\u72ec\u7684\u7a7a\u6808\u5e27&#xff0c;\u7528\u4e8emain\u51fd\u6570\u3002\u8bf7\u6ce8\u610f&#xff0c;\u5176\u4e2d\u6ca1\u6709\u53d8\u91cfx\u7684\u6761\u76ee&#xff0c;\u56e0\u4e3a\u5728\u7a0b\u5e8f\u7684\u8fd9\u4e2a\u9636\u6bb5&#xff0c;\u8be5\u53d8\u91cf\u5c1a\u672a\u58f0\u660e\u3002<\/p>\n<p>\u884c2&#xff0c;\u884c7-9&#xff1a;main\u8c03\u7528foo&#xff0c;\u5c06\u4e00\u4e2a\u65b0\u7684\u6808\u5e27\u538b\u5165\u6808\u4e2d\u3002foo\u58f0\u660e\u4e86y&#xff0c;\u5982\u5176\u6808\u5e27\u4e2dy\u7684\u6761\u76ee\u6240\u793a\u3002<\/p>\n<p>\u884c3&#xff1a;foo\u6267\u884c\u5b8c\u6bd5&#xff0c;\u56e0\u6b64\u5b83\u7684\u6808\u5e27\u4ece\u6808\u4e2d\u5f39\u51fa\u3002main\u58f0\u660e\u4e86x\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5e829f5.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>\u6808\u6ea2\u51fa<\/h6>\n<p>\u6808\u5e76\u975e\u53d6\u4e4b\u4e0d\u5c3d\u7684\u8d44\u6e90&#xff0c;\u5728\u5927\u591a\u6570\u7cfb\u7edf\u4e0a\u53ea\u67091-8MB&#xff0c;\u5728Unix\u7cfb\u7edf\u4e0a&#xff0c;\u53ef\u4ee5\u8f93\u5165ulimit -s \u6765\u67e5\u8be2\u6808\u7a7a\u95f4&#xff08;\u7528KB\u8868\u793a&#xff09;\u3002<\/p>\n<p>\u56e0\u6b64\u5fc5\u987b\u6ce8\u610f\u907f\u514d\u8fc7\u591a\u5d4c\u5957\u51fd\u6570\u8c03\u7528\u800c\u5bfc\u81f4\u6808\u7a7a\u95f4\u8017\u5c3d\u3002\u4f8b\u5982&#xff0c;\u8003\u8651\u4e0b\u9762\u8fd9\u4e2a\u6709\u95ee\u9898\u7684\u7a0b\u5e8f&#xff0c;\u5b83\u672c\u610f\u662f\u8ba1\u7b97\u4e00\u4e2a\u6570\u7684\u9636\u4e58&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">factorial<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> n<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> n <span class=\"token operator\">*<\/span> <span class=\"token function\">factorial<\/span><span class=\"token punctuation\">(<\/span>n <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5e9e661.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u7f3a\u5c11\u57fa\u51c6\u60c5\u51b5\u65f6&#xff0c;factorial\u4f1a\u65e0\u9650\u5730\u63a8\u5165\u6808\u5e27\u3002\u7531\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u53ea\u4e3a\u6808\u5206\u914d\u4e86\u8fd9\u4e48\u591a\u5185\u5b58&#xff0c;\u7a0b\u5e8f\u6700\u7ec8\u4f1a\u8017\u5c3d\u7a7a\u95f4&#xff0c;\u5f15\u53d1\u6bb5\u9519\u8bef\u5e76\u5bfc\u81f4\u7a0b\u5e8f\u88ab\u5f3a\u5236\u7ec8\u6b62\u3002\u8fd9\u79cd\u7279\u5b9a\u60c5\u51b5\u88ab\u79f0\u4e3a\u200b\u6808\u6ea2\u51fa&#xff0c;\u4e5f\u5c31\u662fstack overflow\u200b\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u9012\u5f52\u8981\u6709\u7ec8\u6b62\u6761\u4ef6&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">factorial<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> n<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>n <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> n <span class=\"token operator\">*<\/span> <span class=\"token function\">factorial<\/span><span class=\"token punctuation\">(<\/span>n <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h6>\u6808\u7684\u5c40\u9650<\/h6>\n<ul>\n<li>\u5c40\u90e8\u53d8\u91cf\u7684\u5927\u5c0f\u5728\u7f16\u8bd1\u65f6\u5fc5\u987b\u662f\u4e25\u683c\u5df2\u77e5\u7684\u3002\u4f8b\u5982&#xff0c;\u521b\u5efa\u4e00\u4e2a\u5305\u542bn\u4e2a\u6574\u6570\u7684\u6570\u7ec4&#xff08;\u5176\u4e2dn\u662f\u4ecestd::cin\u8bfb\u53d6\u7684&#xff09;\u5728 C&#043;&#043; \u4e2d\u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002<\/li>\n<li>\u5982\u524d\u6240\u8ff0&#xff0c;\u6808\u7684\u7a7a\u95f4\u662f\u6709\u9650\u7684&#xff0c;\u56e0\u6b64\u5728\u8fd9\u91cc\u5b58\u50a8\u975e\u5e38\u5927\u7684\u5bf9\u8c61&#xff08;\u5982\u5927\u578b\u6570\u7ec4\u3001\u67e5\u627e\u8868\u7b49&#xff09;\u662f\u4e0d\u53ef\u884c\u7684\u3002<\/li>\n<li>\u5c40\u90e8\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u4e0e\u5176\u6240\u5728\u51fd\u6570\u7684\u751f\u547d\u5468\u671f\u7ed1\u5b9a\u3002\u4f60\u4e0d\u80fd\u5728\u6808\u5e27\u4e2d\u521b\u5efa\u4e00\u4e2a\u6bd4\u5176\u6240\u5728\u51fd\u6570\u8c03\u7528\u66f4\u957f\u5bff\u7684\u53d8\u91cf&#xff0c;\u56e0\u4e3a\u5f53\u51fd\u6570\u6267\u884c\u7ed3\u675f\u65f6&#xff0c;\u6808\u5e27\u4e2d\u7684\u6240\u6709\u5185\u5bb9\u90fd\u4f1a\u88ab\u91ca\u653e\u3002<\/li>\n<\/ul>\n<h5>5.1.2 \u5806<\/h5>\n<p>\u200b\u5806\u200b&#xff08;\u4e5f\u79f0\u4e3a\u200b\u81ea\u7531\u5b58\u50a8\u533a\u200b&#xff09;\u5b58\u50a8\u7740\u5927\u5c0f\u53ef\u53d8\u7684\u5185\u5b58\u5757&#xff0c;\u8fd9\u4e9b\u5185\u5b58\u5757\u7684\u5b58\u5728\u65f6\u95f4\u53ef\u4ee5\u8d85\u8fc7\u51fd\u6570\u8c03\u7528\u7684\u751f\u547d\u5468\u671f\u3002\u5b83\u514b\u670d\u4e86\u524d\u9762\u63d0\u5230\u7684\u6808\u7684\u5c40\u9650\u6027&#xff0c;\u4f46\u4ee3\u4ef7\u662f\u6027\u80fd\u7a0d\u5dee&#xff0c;\u5e76\u4e14\u9700\u8981\u7a0b\u5e8f\u5458\u4ed8\u51fa\u989d\u5916\u7684\u7cbe\u529b\u6765\u8fdb\u884c\u7ba1\u7406\u3002<\/p>\n<p>\u5f53\u4f60\u4ece\u5806\u4e2d\u8bf7\u6c42\u5185\u5b58\u65f6&#xff0c;\u5206\u914d\u5668\u5fc5\u987b\u5728\u5185\u90e8\u641c\u7d22\u4e00\u4e2a\u672a\u88ab\u4f7f\u7528\u7684\u533a\u57df&#xff0c;\u8be5\u533a\u57df\u7684\u5927\u5c0f\u81f3\u5c11\u8981\u4e0e\u4f60\u8bf7\u6c42\u7684\u5185\u5b58\u91cf\u76f8\u5f53 \u2014\u2014 \u4e0d\u8fc7\u4f60\u53ef\u80fd\u4f1a\u5f97\u5230\u66f4\u5927\u7684\u533a\u57df&#xff01;\u5982\u679c\u6ca1\u6709\u8db3\u591f\u5927\u7684\u8fde\u7eed\u5757\u53ef\u7528&#xff0c;\u5206\u914d\u5668\u4f1a\u53d1\u51fa\u65e0\u6cd5\u6ee1\u8db3\u8bf7\u6c42\u7684\u4fe1\u53f7\u3002\u5982\u679c\u8bf7\u6c42\u5f97\u5230\u5904\u7406&#xff0c;\u5b83\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u65b0\u5206\u914d\u5185\u5b58\u533a\u57df\u7684\u200b\u6307\u9488\u200b&#xff0c;\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u64cd\u4f5c\u8be5\u533a\u57df\u7684\u5185\u5bb9&#xff0c;\u5e76\u5728\u5c06\u6765\u518d\u6b21\u5f15\u7528\u8be5\u533a\u57df\u3002\u5f53\u4f60\u4f7f\u7528\u5b8c\u8fd9\u5757\u5185\u5b58\u540e&#xff0c;\u53ef\u4ee5&#xff08;\u901a\u8fc7\u6307\u5411\u8be5\u533a\u57df\u7684\u6307\u9488&#xff09;\u5c06\u5176\u5f52\u8fd8\u7ed9\u5206\u914d\u5668&#xff0c;\u4ee5\u4fbf\u4e3a\u5c06\u6765\u7684\u8bf7\u6c42\u91ca\u653e\u7a7a\u95f4\u3002<\/p>\n<p>\u62e5\u6709\u4e00\u4e2a\u72ec\u7acb\u7684\u5806\u89e3\u51b3\u4e86\u6808\u7684\u6240\u6709\u5c40\u9650\u6027&#xff1a;<\/p>\n<ul>\n<li>\u7531\u4e8e\u5206\u914d\u5668\u662f\u4e00\u79cd\u8fd0\u884c\u65f6\u7ed3\u6784&#xff0c;\u4f60\u53ef\u4ee5\u5206\u914d\u4efb\u4f55\u5927\u5c0f\u7684\u5185\u5b58\u5757 \u2014\u2014 \u5305\u62ec\u90a3\u4e9b\u76f4\u5230\u8fd0\u884c\u65f6\u624d\u4f1a\u77e5\u9053\u5927\u5c0f\u7684\u5185\u5b58\u5757\u3002<\/li>\n<li>\u5806\u901a\u5e38\u6bd4\u6808\u5927\u5f97\u591a\u5f97\u591a&#xff0c;\u8fd9\u4f7f\u5f97\u5206\u914d\u975e\u5e38\u5927\u7684\u5185\u5b58\u5757\u6210\u4e3a\u53ef\u80fd\u3002<\/li>\n<li>\u5728\u5806\u4e0a\u521b\u5efa\u7684\u5206\u914d\u72ec\u7acb\u4e8e\u6808\u5e27\u5b58\u5728\u3002\u4e00\u4e2a\u5185\u5b58\u5757\u53ef\u4ee5\u5728\u4e00\u4e2a\u6808\u5e27\u4e2d\u5206\u914d&#xff0c;\u5374\u5728\u53e6\u4e00\u4e2a\u6808\u5e27\u4e2d\u91ca\u653e\u3002<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u5806\u4e0a\u7684\u5185\u5b58\u901a\u5e38\u6bd4\u4f7f\u7528\u6808\u4e0a\u7684\u5185\u5b58\u901f\u5ea6\u6162\u3002\u4e00\u65b9\u9762&#xff0c;\u8fd9\u662f\u56e0\u4e3a\u5728\u5806\u4e0a\u5206\u914d\u5185\u5b58\u9700\u8981\u5206\u914d\u5668\u5bfb\u627e\u4e00\u4e2a\u7a7a\u95f2\u4f4d\u7f6e&#xff0c;\u800c\u6808\u53ea\u9700\u8981\u5c06\u6570\u636e\u538b\u5165\u5f53\u524d\u6808\u9876\u6240\u5728\u7684\u4f4d\u7f6e\u3002\u53e6\u4e00\u65b9\u9762&#xff0c;\u7531\u4e8e\u5806\u5185\u5b58\u7684\u5206\u914d\u65b9\u5f0f&#xff0c;\u5b83\u53ef\u80fd\u4f1a\u53d8\u5f97\u788e\u7247\u5316&#xff0c;\u5e76\u4e14\u6bd4\u6808\u5185\u5b58\u5206\u5e03\u5f97\u66f4\u5206\u6563\u3002\u5982\u679c\u5904\u7406\u5668\u8bbf\u95ee\u7684\u5185\u5b58\u4f4d\u7f6e\u5f80\u5f80\u66f4\u96c6\u4e2d&#xff08;\u4f8b\u5982\u6808&#xff09;&#xff0c;\u800c\u4e0d\u662f\u5206\u5e03\u66f4\u5206\u6563&#xff08;\u5806&#xff09;&#xff0c;\u90a3\u4e48\u5b83\u7684\u5de5\u4f5c\u901f\u5ea6\u4f1a\u66f4\u5feb\u3002\u8fd9\u88ab\u79f0\u4e3a\u200b\u5c40\u90e8\u6027\u539f\u7406\u200b\u3002<\/p>\n<h4>5.2 \u6307\u9488<\/h4>\n<p>\u5728\u8bb8\u591a\u5e38\u89c1\u7684\u7f16\u7a0b\u8bed\u8a00\u4e2d&#xff0c;\u4f8b\u5982 Python&#xff0c;\u5730\u5740\u7a7a\u95f4\u7684\u4f7f\u7528\u662f\u81ea\u52a8\u4e3a\u4f60\u7ba1\u7406\u7684\u3002\u5728 C&#043;&#043; \u4e2d&#xff0c;\u5927\u90e8\u5206\u60c5\u51b5\u4e5f\u662f\u5982\u6b64&#xff0c;\u7136\u800c&#xff0c;\u4f5c\u4e3a\u4e00\u79cd\u7cfb\u7edf\u7f16\u7a0b\u8bed\u8a00&#xff0c;C&#043;&#043; \u8fd8\u901a\u8fc7\u4e00\u79cd\u88ab\u79f0\u4e3a\u6307\u9488\u7684\u8bed\u8a00\u7279\u6027&#xff0c;\u8ba9\u4f60\u80fd\u591f\u76f4\u63a5\u8bbf\u95ee\u8fd9\u79cd\u5185\u5b58\u3002<\/p>\n<p>C&#043;&#043; \u4e2d\u7684\u6307\u9488\u65e2\u662f\u5185\u5b58\u4e2d\u5bf9\u8c61\u7684\u5730\u5740&#xff0c;\u4e5f\u662f\u6211\u4eec\u5728\u4ee3\u7801\u4e2d\u8868\u793a\u8be5\u5730\u5740\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u5728\u5b57\u8282\u53ef\u5bfb\u5740\u5185\u5b58&#xff08;\u5927\u591a\u6570\u8ba1\u7b97\u673a\u90fd\u4f7f\u7528\u8fd9\u79cd\u5185\u5b58&#xff09;\u4e2d&#xff0c;\u7a0b\u5e8f\u5730\u5740\u7a7a\u95f4\u4e2d\u7684\u6bcf\u4e2a\u5b57\u8282\u90fd\u7531\u4e00\u4e2a\u4ece 0 \u5f00\u59cb\u5e76\u9010\u4e2a\u9012\u589e\u7684\u6570\u5b57\u6765\u6807\u8bc6 \u2014\u2014 \u8fd9\u5c31\u662f\u6bcf\u4e2a\u5b57\u8282\u7684\u200b\u5730\u5740\u200b\u3002\u4e00\u4e2a\u5bf9\u8c61\u5728\u5185\u5b58\u4e2d\u53ef\u80fd\u5360\u7528\u591a\u4e2a\u5b57\u8282&#xff0c;\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;\u6574\u4e2a\u5bf9\u8c61\u7684\u5730\u5740\u5c31\u662f\u5176\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u5730\u5740&#xff08;\u5373\u5730\u5740\u503c\u6700\u5c0f\u7684\u90a3\u4e2a\u5b57\u8282\u7684\u5730\u5740&#xff09;\u3002\u4f8b\u5982&#xff0c;\u5728\u5927\u591a\u6570\u7cfb\u7edf\u4e0a&#xff0c;\u4e00\u4e2aint\u7c7b\u578b\u5360\u7528 4 \u4e2a\u5b57\u8282&#xff08;\u5373 32 \u4f4d&#xff09;\u7684\u7a7a\u95f4\u3002\u5982\u679c\u6211\u4eec\u53bb\u67e5\u770b\u4e00\u4e2a\u6574\u6570\u7684\u5185\u5b58&#xff0c;\u53ef\u80fd\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e0b\u9762\u8fd9\u6837\u7684\u60c5\u51b5&#xff1a;<\/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> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">106<\/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><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5eb4ca7.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5728\u8be5\u7a0b\u5e8f\u7684\u67d0\u6b21\u7279\u5b9a\u8fd0\u884c\u4e2d&#xff0c;x\u7684\u5185\u5b58\u8d77\u59cb\u5730\u5740\u4e3a0x7fff4a5ff71c\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u4e3a\u7b80\u6d01\u8d77\u89c1&#xff0c;\u5730\u5740\u901a\u5e38\u4ee5\u5341\u516d\u8fdb\u5236&#xff08;\u57fa\u6570 16&#xff09;\u8868\u793a&#xff0c;\u800c\u975e\u5341\u8fdb\u5236&#xff08;\u57fa\u6570 10&#xff09;\u3002x\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u662f01101010&#xff0c;\u5176\u5bf9\u5e94\u7684\u4e8c\u8fdb\u5236\u6570\u503c\u4e3a106\u3002x\u4e0a\u4e0b\u7684\u5185\u5b58\u60c5\u51b5\u672a\u77e5&#xff0c;\u53ef\u80fd\u662f\u4efb\u4f55\u503c\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528operator&amp;&#xff08;\u88ab\u79f0\u4e3a\u200b\u53d6\u5730\u5740\u8fd0\u7b97\u7b26\u200b&#xff09;\u6765\u83b7\u53d6\u6307\u5411x\u7684\u6307\u9488&#xff0c;\u8be5\u8fd0\u7b97\u7b26\u63a5\u6536\u4e00\u4e2a\u53d8\u91cf\u5e76\u8fd4\u56de\u6307\u5411\u8be5\u53d8\u91cf\u7684\u6307\u9488&#xff08;\u5373\u8be5\u53d8\u91cf\u7684\u5730\u5740&#xff09;\u3002\u8003\u8651\u5bf9\u4e0a\u8ff0\u4ee3\u7801\u7247\u6bb5\u7a0d\u4f5c\u4fee\u6539\u7684\u7248\u672c&#xff1a;<\/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> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">106<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> px <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>x<span class=\"token punctuation\">;<\/span><br \/>\n  std<span class=\"token operator\">::<\/span>cout<span class=\"token operator\">&lt;&lt;<\/span> x <span class=\"token operator\">&lt;&lt;<\/span>std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ 106<\/span><br \/>\n  std<span class=\"token operator\">::<\/span>cout<span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token operator\">*<\/span>px <span class=\"token operator\">&lt;&lt;<\/span>std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ 106<\/span><br \/>\n  std<span class=\"token operator\">::<\/span>cout<span class=\"token operator\">&lt;&lt;<\/span> px <span class=\"token operator\">&lt;&lt;<\/span>std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ 0x50527c<\/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>x_ptr\u662f\u6307\u5411x\u7684\u6307\u9488\u3002\u4ece\u6982\u5ff5\u4e0a\u8bb2&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8ba4\u4e3ax_ptr\u6b63\u6307\u5411x\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5edfbf1.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5b9e\u9645\u4e0a&#xff0c;x_ptr\u5b58\u50a8\u7740x\u7684\u5730\u5740\u3002\u66f4\u5177\u4f53\u5730\u8bf4&#xff0c;x_ptr\u672c\u8eab\u662f\u4e00\u4e2a\u6570\u5b57&#xff0c;\u5176\u503c\u4e3ax\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u5730\u5740\u3002\u6ce8\u610f&#xff0c;x_ptr\u5360\u7528 8 \u4e2a\u5b57\u8282\u7684\u7a7a\u95f4&#xff08;\u4e8b\u5b9e\u4e0a&#xff0c;\u5728 64 \u4f4d\u7cfb\u7edf\u4e0a&#xff0c;\u6240\u6709\u6307\u9488\u90fd\u5360\u7528 8 \u4e2a\u5b57\u8282\u7684\u7a7a\u95f4&#xff09;\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5ef1bd9.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5982\u679c\u6211\u4eec\u8981\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\u6253\u5370\u51fax_ptr&#xff0c;\u6211\u4eec\u53ea\u4f1a\u770b\u5230\u5b83\u6240\u5305\u542b\u7684\u5730\u5740&#xff08;0x7fff4a5ff71c&#xff09;\u3002\u4e0d\u8fc7&#xff0c;\u5bf9\u4e8e\u4e00\u4e2a\u6307\u9488&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u89e3\u5f15\u7528\u4ee5\u83b7\u53d6\u5b83\u6240\u6307\u5411\u7684\u5b9e\u9645\u503c&#xff1a;<\/p>\n<p>std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> x <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\\\\n&#034;<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ Prints 106<\/span><br \/>\nstd<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> x_ptr <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\\\\n&#034;<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ Prints 0x7fff4a5ff71c<\/span><br \/>\nstd<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token operator\">*<\/span>x_ptr <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\\\\n&#034;<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ Prints 106<\/span><\/p>\n<p>\u6240\u4ee5&#xff0c;\u4e00\u4e2a\u6307\u9488\u5c31\u662f\u4e00\u4e2a\u6570&#xff01;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5f1972b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u73b0\u5728\u6211\u4eec\u5c06\u8ba8\u8bba\u6307\u9488\u7684\u8bed\u6cd5&#xff0c;\u5305\u62ec\u5b83\u4eec\u5982\u4f55\u88ab\u89e3\u5f15\u7528\u3002<\/p>\n<h5>5.2.1 \u6307\u9488\u7c7b\u578b<\/h5>\n<p>\u5bf9\u4e8e\u4efb\u4f55\u7c7b\u578bT&#xff0c;T* \u662f\u6307\u5411\u7c7b\u578b\u4e3aT \u7684\u5bf9\u8c61\u7684\u6307\u9488\u7c7b\u578b\u3002\u5728\u5e95\u5c42&#xff0c;\u6bcf\u4e2a\u6307\u9488\u90fd\u8868\u793a\u4e3a\u5bf9\u8c61\u8d77\u59cb\u5b57\u8282\u7684\u5730\u5740 \u2014\u2014 \u90a3\u4e48\u4e3a\u4ec0\u4e48\u8981\u5305\u542b\u6709\u5173\u7c7b\u578b\u7684\u4fe1\u606f\u5462&#xff1f;\u8bf7\u8bb0\u4f4f&#xff0c;C&#043;&#043; \u662f\u4e00\u79cd\u7c7b\u578b\u5b89\u5168\u7684\u8bed\u8a00&#xff08;\u89c1\u7b2c1\u8282&#xff09;&#xff0c;\u56e0\u6b64\u6211\u4eec\u6240\u6307\u5411\u7684\u5bf9\u8c61\u662fint\u8fd8\u662fstd::string\u81f3\u5173\u91cd\u8981&#xff0c;\u56e0\u4e3a\u8fd9\u4f1a\u6539\u53d8\u6307\u5411\u5bf9\u8c61\u6240\u652f\u6301\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u5728 64 \u4f4d\u7cfb\u7edf\u4e0a&#xff0c;\u6307\u9488\u7684\u5927\u5c0f\u59cb\u7ec8\u4e3a 64 \u4f4d&#xff08;8 \u5b57\u8282&#xff09;\u3002\u5728 32 \u4f4d\u7cfb\u7edf\u4e0a&#xff0c;\u6307\u9488\u4f1a\u5360\u7528 32 \u4f4d&#xff08;4 \u5b57\u8282&#xff09;\u3002\u5b9e\u9645\u4e0a&#xff0c;\u8fd9\u4e3a\u7a0b\u5e8f\u53ef\u5229\u7528\u7684\u5185\u5b58\u91cf\u8bbe\u5b9a\u4e86\u4e00\u4e2a\u4e0a\u9650 \u2014\u201432 \u4f4d\u673a\u5668\u4e0a\u7684\u7a0b\u5e8f\u6700\u591a\u53ef\u5bfb\u5740 2\u00b3\u00b2B\u22484GB\u3002\u4e8b\u5b9e\u4e0a&#xff0c;\u8fd9\u662f\u8f6c\u5411 64 \u4f4d\u673a\u5668\u7684\u4e3b\u8981\u52a8\u673a\u4e4b\u4e00&#xff1a;\u5b83\u4eec\u80fd\u591f\u5bfb\u5740&#xff08;\u4ece\u800c\u5229\u7528&#xff09;\u591a\u5f97\u591a\u7684\u5185\u5b58&#xff01;<\/p>\n<h6>*\u89e3\u5f15\u7528<\/h6>\n<p>\u7ed9\u5b9a\u4e00\u4e2aT* \u6307\u9488&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7T \u7c7b\u578b\u7684\u200b\u95f4\u63a5\u8fd0\u7b97\u7b26\u200b&#xff0c;\u5373operator* \u6765\u83b7\u53d6\u5b83\u6240\u6307\u5411\u7684\u503c\u3002\u8fd9\u88ab\u79f0\u4e3a\u5bf9\u6307\u9488\u8fdb\u884c\u200b\u89e3\u5f15\u7528\u200b\u3002\u51c6\u786e\u5730\u8bf4&#xff0c;operator* \u4f1a\u8fd4\u56de\u4e00\u4e2aT&amp;&#xff0c;\u4e5f\u5c31\u662f\u5bf9T \u7684\u5f15\u7528\u3002\u4e3a\u4ec0\u4e48\u5462&#xff1f;\u8fd9\u4e00\u6280\u672f\u7ec6\u8282\u610f\u5473\u7740&#xff0c;\u89e3\u5f15\u7528\u6307\u9488\u4e0d\u4f1a\u5bf9\u6240\u6307\u5411\u7684\u5bf9\u8c61\u8fdb\u884c\u4efb\u4f55\u590d\u5236 \u2014\u2014 \u5b83\u4ec5\u4ec5\u662f\u8bbf\u95ee\u8be5\u5bf9\u8c61\u5df2\u5b58\u5728\u7684\u5185\u5b58\u3002\u6b64\u5916&#xff0c;\u8fd9\u4f7f\u5f97\u6211\u4eec\u80fd\u591f\u4f7f\u7528\u95f4\u63a5\u5bfb\u5740\u8fd0\u7b97\u7b26\u6765\u4fee\u6539\u5e95\u5c42\u6570\u636e&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">106<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> x_ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>x<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token operator\">*<\/span>x_ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">107<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u884c2&#xff1a;<\/p>\n<p>x_ptr\u6307\u5411x\u7684\u5730\u5740\u3002<\/p>\n<p>\u884c3&#xff1a;<\/p>\n<p>\u7531\u4e8e\u95f4\u63a5\u5f15\u7528\u8fd4\u56de\u4e00\u4e2aint&amp;&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7x_ptr\u4fee\u6539x&#xff0c;\u5c06\u5176\u4ece106\u6539\u4e3a107\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5f37a6b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>-&gt;\u89e3\u5f15\u7528\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458<\/h6>\n<p>\u5982\u679cT\u6070\u597d\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53&#xff0c;\u4f8b\u5982std::pair&lt;double, double&gt;&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6210\u5458\u8bbf\u95ee\u8fd0\u7b97\u7b26operator-&gt; \u76f4\u63a5\u8bbf\u95ee\u5176\u6210\u5458\u3002\u8fd9\u548c\u5148\u89e3\u5f15\u7528\u6307\u9488\u518d\u8bbf\u95ee\u6210\u5458\u662f\u4e00\u6837\u7684\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>std<span class=\"token operator\">::<\/span>pair<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">double<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span> my_pair <span class=\"token punctuation\">{<\/span> <span class=\"token number\">10<\/span><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\">auto<\/span><span class=\"token operator\">*<\/span> ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>my_pair<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> second <span class=\"token operator\">&#061;<\/span> ptr<span class=\"token operator\">-&gt;<\/span>second<span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ Same as (*ptr).second<\/span><\/p>\n<p>\u884c2&#xff1a;<\/p>\n<p>ptr\u6307\u5411my_pair\u3002\u6ce8\u610f\u4f7f\u7528auto\u6765\u8ba9\u7f16\u8bd1\u5668\u63a8\u65ad\u7c7b\u578b\u3002<\/p>\n<p>\u884c3&#xff1a;<\/p>\n<p>-&gt;\u8fd0\u7b97\u7b26\u4f1a\u5bf9\u6240\u6307\u5411\u5bf9\u8c61\u4e2d\u7684\u7279\u5b9a\u6210\u5458\u8fdb\u884c\u200b\u89e3\u5f15\u7528\u200b\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5f4f664.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>const\u4e0e\u6307\u9488<\/h6>\n<p>\u6bcf\u4e2aT \u4e5f\u6709\u4e00\u79cd\u6307\u5411\u5e38\u91cf\u7684\u6307\u9488 \u7c7b\u578b&#xff0c;\u5373const T*&#xff08;\u4e5f\u53ef\u5199\u6210T const*&#xff09;&#xff0c;\u5b83\u8868\u793a\u4e00\u4e2a\u6307\u5411const T \u7684\u6307\u9488\u3002\u6211\u4eec\u4e0d\u80fd\u4fee\u6539\u8fd9\u79cd\u6307\u9488\u6240\u6307\u5411\u7684\u5bf9\u8c61\u7684\u5185\u5bb9\u3002\u4e0d\u8fc7&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4fee\u6539\u6307\u9488\u672c\u8eab\u6240\u6307\u5411\u7684\u5bf9\u8c61\u3002<\/p>\n<p><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">106<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> y <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">107<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>x<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ *ptr &#061; 107;        \/\/ Not allowed, &#096;ptr&#096; points to &#096;const int&#096;<\/span><br \/>\nptr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>y<span class=\"token punctuation\">;<\/span>             <span class=\"token comment\">\/\/ However, we can change where &#096;ptr&#096; points to<\/span><\/p>\n<p>\u4e8b\u5b9e\u4e0a&#xff0c;\u5982\u679c\u6211\u4eec\u60f3\u9632\u6b62\u6307\u9488\u672c\u8eab\u88ab\u4fee\u6539&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u200b\u5e38\u91cf\u6307\u9488\u200b&#xff0c;\u4f8b\u5982T* const\u3002\u6307\u9488\u672c\u8eab\u65e0\u6cd5\u88ab\u4fee\u6539&#xff08;\u5373\u4e0d\u80fd\u6307\u5411\u53e6\u4e00\u4e2a\u5bf9\u8c61&#xff09;&#xff0c;\u4f46\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u4fee\u6539\u5176\u6307\u5411\u7684\u5e95\u5c42\u5bf9\u8c61\u3002\u56e0\u6b64&#xff0c;\u6bcf\u4e2aT\u90fd\u6709\u56db\u79cd\u6307\u9488\u7c7b\u578b&#xff0c;\u5982\u4e0b\u8868\u6240\u793a&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5f779bf.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>nullptr<\/h6>\n<p>\u6709\u4e00\u79cd\u7279\u6b8a\u7684\u503c&#xff0c;nullptr&#xff0c;\u5b83\u8868\u793a\u6307\u5411\u65e0\u5bf9\u8c61\u7684\u6307\u9488\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u8868\u793a\u503c\u7684\u7f3a\u5931\u3002nullptr\u53ef\u4ee5\u88ab\u5f3a\u5236\u8f6c\u6362\u4e3a\u4e0a\u8ff0\u4efb\u4f55\u4e00\u79cd\u6307\u9488\u7c7b\u578b\u4ee5\u53ca\u4efb\u4f55\u7c7b\u578bT&#xff0c;\u5e76\u4e14\u5728\u5e95\u5c42&#xff0c;nullptr\u59cb\u7ec8\u5b58\u50a8\u7740\u7279\u6b8a\u5730\u57400\u3002\u5c0f\u5fc3&#xff01;\u4f60\u4e0d\u80fd\u89e3\u5f15\u7528nullptr\u200b&#xff0c;\u56e0\u4e3a\u5b83\u4e0d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\u3002\u5c1d\u8bd5\u8fd9\u6837\u505a&#xff0c;\u65e0\u8bba\u662f\u901a\u8fc7operator*\u8fd8\u662foperator-&gt;&#xff0c;\u90fd\u4f1a\u5bfc\u81f4\u6bb5\u9519\u8bef\u3002<\/p>\n<p><span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ Either of these commented lines would crash:<\/span><br \/>\n<span class=\"token comment\">\/\/  int x &#061; *ptr;<\/span><br \/>\n<span class=\"token comment\">\/\/  *ptr &#061; 106;<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5f8ffa3.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5728 C&#043;&#043; \u4e2d&#xff0c;nullptr\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u7c7b\u578b&#xff0c;nullptr_t\u3002nullptr_t\u552f\u4e00\u7684\u5b9e\u4f8b\u662fnullptr&#xff0c;\u5e76\u4e14\u5b83\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a\u4efb\u4f55\u6307\u9488\u7c7b\u578b\u7684\u5b9e\u4f8b\u3002<\/p>\n<h5>5.2.2 \u6307\u5411\u5806\u7684\u6307\u9488<\/h5>\n<p>\u5728\u73b0\u4ee3 C&#043;&#043; \u4e2d&#xff0c;\u4e0d\u518d\u5efa\u8bae\u4f7f\u7528\u539f\u59cb\u6307\u9488&#xff08;\u4f8b\u5982T*&#xff09;\u6765\u5f15\u7528\u5806\u5206\u914d&#xff0c;\u56e0\u4e3a\u5982\u679c\u5fd8\u8bb0\u91ca\u653e\u5b83\u4eec&#xff0c;\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u3002\u8003\u8651\u6539\u7528\u200b\u667a\u80fd\u6307\u9488\u200b&#xff0c;\u4f8b\u5982unique_ptr\u548cshared_ptr&#xff0c;\u5b83\u4eec\u4f1a\u81ea\u52a8\u8fdb\u884c\u91ca\u653e\u3002\u8fd9\u4e9b\u5185\u5bb9\u5c06\u5728\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u8ba8\u8bba\u3002<\/p>\n<h6>new<\/h6>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62&#xff0c;\u6211\u4eec\u5c55\u793a\u7684\u793a\u4f8b\u4e2d\u5305\u542b\u4e86\u6307\u5411\u6808\u533a\u57df\u7684\u6307\u9488&#xff0c;\u4f8b\u5982x_ptr&#xff0c;\u5b83\u6307\u5411\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cfx\u3002\u8fd9\u5728 C&#043;&#043; \u4e2d\u5e76\u4e0d\u5e38\u89c1&#xff0c;\u56e0\u4e3a\u5f15\u7528&#xff08;\u5728\u524d\u4e00\u7ae0\u4e2d\u8ba8\u8bba\u8fc7&#xff0c;\u4e0b\u9762\u8fd8\u4f1a\u8be6\u7ec6\u4ecb\u7ecd&#xff09;\u66f4\u5e38\u7528\u4e8e\u5b9e\u73b0\u76f8\u540c\u7684\u529f\u80fd\u3002\u4f60\u66f4\u5e38\u770b\u5230\u6307\u9488\u88ab\u7528\u4e8e\u5f15\u7528\u5806\u4e0a\u7684\u5206\u914d\u3002\u5982\u524d\u6240\u8ff0&#xff0c;\u5806\u5b58\u50a8\u7684\u662f\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58&#xff0c;\u5176\u751f\u547d\u5468\u671f\u53ef\u4ee5\u8d85\u8fc7\u51fd\u6570\u8c03\u7528\u3002\u8981\u5728\u5806\u4e0a\u5206\u914d\u4e00\u4e2aT\u7c7b\u578b\u7684\u5bf9\u8c61&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528operator new\u5411\u5206\u914d\u5668\u8bf7\u6c42&#xff1a;<\/p>\n<p>T* ptr &#061; new T;<\/p>\n<p>\u8bf7\u6ce8\u610f&#xff0c;\u6b64\u7248\u672c\u7684new\u4e0d\u4f1a\u521d\u59cb\u5316T\u3002\u5b83\u7684\u5185\u5b58\u5c06\u662f\u5206\u914d\u7684\u5757\u4e2d\u9057\u7559\u7684\u4efb\u4f55\u5185\u5bb9&#xff0c;\u901a\u5e38\u662f\u5783\u573e\u6570\u636e\u3002\u8981\u5b9e\u9645\u521d\u59cb\u5316\u5bf9\u8c61&#xff0c;\u4f60\u53ef\u4ee5\u4f7f\u7528\u7edf\u4e00\u521d\u59cb\u5316&#xff0c;\u4f8b\u5982:<\/p>\n<p>T* ptr &#061; new T { \/* Args to initialize T *\/ };<\/p>\n<p>\u6216\u8005\u503c\u521d\u59cb\u5316&#xff1a;<\/p>\n<p>T* ptr &#061; new T();<\/p>\n<p>\u4e3a\u4e86\u770b\u51fa\u5dee\u5f02&#xff0c;\u8003\u8651\u4ee5\u4e0b\u60c5\u51b5&#xff0c;T &#061; std::pair&lt;int, double&gt;&#xff1a;<\/p>\n<p><span class=\"token keyword\">auto<\/span> ptr1 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> std<span class=\"token operator\">::<\/span>pair<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> ptr2 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> std<span class=\"token operator\">::<\/span>pair<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token number\">106<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3.14<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">auto<\/span> ptr3 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> std<span class=\"token operator\">::<\/span>pair<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6211\u4eec\u65e0\u6cd5\u786e\u5207\u77e5\u9053*ptr1\u5305\u542b\u4ec0\u4e48&#xff0c;\u56e0\u4e3a\u5b83\u6ca1\u6709\u88ab\u521d\u59cb\u5316\u3002\u4e0d\u8fc7&#xff0c;*ptr2\u80af\u5b9a\u662f\u7528106\u548c3.14\u521d\u59cb\u5316\u7684&#xff0c;\u800c*ptr3\u662f\u8fdb\u884c\u4e86\u503c\u521d\u59cb\u5316\u7684&#xff0c;\u5176\u6210\u5458\u90fd\u88ab\u96f6\u521d\u59cb\u5316\u4e86\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5f9f7ce.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>delete<\/h6>\n<p>\u4e00\u65e6\u4f60\u6709\u4e86\u4e00\u4e2a\u6307\u5411\u5806\u7684T*&#xff0c;\u4f60\u5c31\u53ef\u4ee5\u89e3\u5f15\u7528\u5b83\u3001\u5c06\u8be5\u6307\u9488\u4f20\u9012\u7ed9\u5176\u4ed6\u51fd\u6570\u3001\u628a\u5b83\u5b58\u50a8\u5728\u53e6\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u4e2d\u7b49\u7b49\u3002\u4f46\u662f&#xff0c;\u4e00\u65e6\u4f60\u7528\u5b8c\u8fd9\u4e2a\u5185\u5b58\u533a\u57df&#xff0c;\u5fc5\u987b\u8bb0\u5f97\u8981\u8fdb\u884c\u200b\u91ca\u653e\u200b\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5c06new\u8fd4\u56de\u7684\u540c\u4e00\u4e2a\u6307\u9488\u4f20\u9012\u7ed9operator delete\u6765\u5b9e\u73b0&#xff1a;<\/p>\n<p>delete ptr;<\/p>\n<p>\u8fd9\u4f1a\u91ca\u653e\u7531ptr\u6307\u5411\u7684\u5185\u5b58\u3002\u5bf9\u4e4b\u524d\u672a\u7531new\u8fd4\u56de\u7684\u6307\u9488\u8c03\u7528delete\u662f\u65e0\u6548\u7684&#xff0c;\u8bd5\u56fe\u5bf9\u540c\u4e00\u4e2a\u6307\u9488\u8fdb\u884c\u4e24\u6b21delete\u64cd\u4f5c\u4e5f\u662f\u5982\u6b64\u3002\u8fd9\u6761\u89c4\u5219\u7684\u4e00\u4e2a\u4f8b\u5916\u662fnullptr&#xff1a;\u5bf9nullptr\u6267\u884cdelete\u64cd\u4f5c\u59cb\u7ec8\u662f\u6709\u6548\u7684&#xff0c;\u5e76\u4e14\u4e0d\u4f1a\u4ea7\u751f\u4efb\u4f55\u6548\u679c\u3002\u672a\u80fddelete\u7528new\u5206\u914d\u7684\u6307\u9488\u4e0d\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83&#xff0c;\u4f46\u4f1a\u5bfc\u81f4\u200b\u5185\u5b58\u6cc4\u6f0f\u200b&#xff0c;\u4f7f\u7a0b\u5e8f\u4f7f\u7528\u7684\u5185\u5b58\u8d85\u8fc7\u5176\u6240\u9700\u3002<\/p>\n<h6>new[] \u548c delete[]<\/h6>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b&#xff0c;\u6211\u4eec\u4e0d\u60f3\u4e3a\u5355\u4e2a\u5bf9\u8c61\u5206\u914d\u7a7a\u95f4&#xff0c;\u800c\u662f\u5e0c\u671b\u4e00\u6b21\u4e3a\u591a\u4e2a\u5bf9\u8c61\u5206\u914d\u7a7a\u95f4\u3002C&#043;&#043; \u901a\u8fc7\u6570\u7ec4\u5206\u914d\u548coperator new[]\u6765\u652f\u6301\u8fd9\u4e00\u70b9&#xff1a;<\/p>\n<p>T* ptr &#061; new T[n];<\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u5206\u914d\u4e86\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df&#xff0c;\u5176\u5927\u5c0f\u8db3\u4ee5\u5bb9\u7eb3n\u4e2aT\u5b9e\u4f8b\u3002\u91cd\u8981\u7684\u662f&#xff0c;n\u53ef\u4ee5\u662f\u4e00\u4e2a\u52a8\u6001\u786e\u5b9a\u7684\u503c \u2014\u2014 \u5b83\u4e0d\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u5df2\u77e5&#xff0c;\u8fd9\u4f7f\u6211\u4eec\u80fd\u591f\u514b\u670d\u6808\u5185\u5b58 \/ \u5c40\u90e8\u53d8\u91cf\u6240\u53d7\u7684\u9759\u6001\u5927\u5c0f\u9650\u5236\u3002\u8fd9\u79cd\u8bed\u6cd5\u4e5f\u4e0d\u4f1a\u521d\u59cb\u5316\u8be5\u533a\u57df\u4e2d\u7684\u4efb\u4f55\u5143\u7d20\u3002\u5982\u679c\u6211\u4eec\u60f3\u8981\u521d\u59cb\u5316\u8fd9\u4e9b\u5143\u7d20&#xff0c;\u53ef\u4ee5\u4f7f\u7528&#xff1a;<\/p>\n<p>T<span class=\"token operator\">*<\/span> ptr1 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> T<span class=\"token punctuation\">[<\/span>n<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nT<span class=\"token operator\">*<\/span> ptr2 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> T<span class=\"token punctuation\">[<\/span>n<span class=\"token punctuation\">]<\/span> <span class=\"token punctuation\">{<\/span> t1<span class=\"token punctuation\">,<\/span> t2<span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/* &#8230; *\/<\/span><span class=\"token punctuation\">,<\/span> tn <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4f8b\u5982&#xff0c;\u8003\u8651\u8fd9\u6bb5\u4ee3\u7801\u6240\u4ea7\u751f\u7684\u5185\u5b58\u5185\u5bb9&#xff1a;<\/p>\n<p><span class=\"token keyword\">double<\/span><span class=\"token operator\">*<\/span> ptr0 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token keyword\">double<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span><span class=\"token operator\">*<\/span> ptr1 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token keyword\">double<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span><span class=\"token operator\">*<\/span> ptr3 <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token keyword\">double<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/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 punctuation\">;<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5fbe107.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5f53\u4f7f\u7528new[]\u5206\u914d\u6570\u7ec4\u65f6&#xff0c;\u5728\u4f7f\u7528\u5b8c\u8be5\u6570\u7ec4\u540e&#xff0c;\u5fc5\u987b\u4f7f\u7528\u76f8\u5e94\u7684delete[]\u3002 \u5c1d\u8bd5\u4f7f\u7528delete&#xff08;\u4e0d\u5e26[]&#xff09;\u6765\u91ca\u653e\u8fd9\u6837\u7684\u6307\u9488\u662f\u65e0\u6548\u7684\u3002<\/p>\n<p>T<span class=\"token operator\">*<\/span> ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> T<span class=\"token punctuation\">[<\/span>n<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">delete<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> ptr<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6ce8\u610f&#xff1a;\u6307\u5411\u5bf9\u8c61\u7684\u6307\u9488\u548c\u6307\u5411\u6570\u7ec4\u7684\u6307\u9488\u5728\u8bed\u6cd5\u4e0a\u6ca1\u6709\u533a\u522b\u3002\u7a0b\u5e8f\u5458\u6709\u8d23\u4efb\u4e86\u89e3\u4e24\u8005\u4e4b\u95f4\u7684\u5dee\u5f02\u5e76\u4f7f\u7528\u9002\u5f53\u7684\u64cd\u4f5c&#xff0c;\u4f8b\u5982\u5bf9\u5176\u8c03\u7528\u6b63\u786e\u7248\u672c\u7684delete\u3002<\/p>\n<h5>5.2.3 \u6307\u9488\u8fd0\u7b97<\/h5>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\u6307\u9488T*&#xff0c;\u6211\u4eec\u5982\u4f55\u8bbf\u95ee\u7b2c i \u4e2a\u5143\u7d20&#xff1f;\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u200b\u6307\u9488\u7b97\u672f\u200b\u3002\u56de\u60f3\u4e00\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u79cd\u7c7b\u578bT\u5728\u7f16\u8bd1\u65f6\u90fd\u6709\u56fa\u5b9a\u7684\u5927\u5c0f\u3002<\/li>\n<li>\u6570\u7ec4\u5206\u914d&#xff08;\u7531new[]\u8fd4\u56de&#xff09;\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u7684\u3002<\/li>\n<\/ul>\n<p>\u7b2c\u4e00\u4e2a\u4e8b\u5b9e\u4f7f\u7f16\u8bd1\u5668\u80fd\u591f\u7cbe\u786e\u77e5\u9053\u4e3a\u4e00\u4e2a\u5305\u542bn\u4e2aT\u7c7b\u578b\u5143\u7d20\u7684\u6570\u7ec4\u5206\u914d\u591a\u5c11\u5b57\u8282 \u2014\u2014 \u5b9e\u9645\u4e0a&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8c03\u7528sizeof(T)\u6765\u83b7\u53d6T\u5728\u7f16\u8bd1\u65f6\u7684\u5927\u5c0f&#xff0c;\u56e0\u6b64n * sizeof(T)\u662f\u8c03\u7528new T[n]\u5fc5\u987b\u5206\u914d\u7684\u6700\u5c0f\u5b57\u8282\u6570\u3002<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u4e8b\u5b9e\u4e0e\u7b2c\u4e00\u4e2a\u4e8b\u5b9e\u76f8\u7ed3\u5408&#xff0c;\u8ba9\u6211\u4eec\u80fd\u591f\u77e5\u9053\u6570\u7ec4\u4e2d\u5404\u4e2a\u5143\u7d20\u7684\u5730\u5740\u3002\u5982\u4e0b\u4f8b\u6240\u793a&#xff0c;\u5c06\u4e00\u4e2a\u6574\u6570\u52a0\u5230\u6307\u9488\u4e0a&#xff0c;\u4f1a\u4f7f\u8be5\u6307\u9488\u7684\u5730\u5740\u4ee5sizeof(T)\u7684\u500d\u6570 \u9012\u589e&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> arr <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token keyword\">int<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> ptr_to_2nd <span class=\"token operator\">&#061;<\/span> arr <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> ptr_to_3rd <span class=\"token operator\">&#061;<\/span> arr <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>arr\u6307\u5411\u5df2\u5206\u914d\u6570\u7ec4\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002\u7ed9arr\u52a0\u4e0a1\u4f1a\u5f97\u5230\u6307\u5411\u5185\u5b58\u4e2darr\u540e\u9762\u7b2c1\u4e2a\u5143\u7d20\u7684\u6307\u9488&#xff0c;\u52a0\u4e0a2\u4f1a\u5f97\u5230\u6307\u5411arr\u540e\u9762\u7b2c2\u4e2a\u5143\u7d20\u7684\u6307\u9488&#xff0c;\u4ee5\u6b64\u7c7b\u63a8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5fdc4e8.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5728\u5e95\u5c42&#xff0c;\u7ed9\u4e00\u4e2a\u6570\u5b57\u52a0\u4e0a\u4e00\u4e2a\u6574\u6570&#xff0c;\u4f1a\u4ece\u5176\u5e95\u5c42\u5730\u5740\u589e\u52a0\u6216\u51cf\u5c11sizeof(T)\u5b57\u8282\u7684\u500d\u6570\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;sizeof(int) &#061; 4&#xff0c;\u6240\u4ee5\u4f8b\u5982arr &#043; 1&#xff0c;\u5c31\u662f\u7ed9arr\u7684\u5e95\u5c42\u5730\u5740\u589e\u52a0 4 \u4e2a\u5b57\u8282\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073559-6986eb5feb0a8.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6211\u4eec\u901a\u5e38\u5e0c\u671b\u8bbf\u95ee\u6570\u7ec4\u4e2d\u4e0d\u540c\u4f4d\u7f6e\u7684\u5143\u7d20\u3002\u4f7f\u7528\u6307\u9488&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u89e3\u5f15\u7528\u6765\u83b7\u53d6&#xff0c;\u4f8b\u5982*(arr &#043; 1)&#xff0c;\u4ee5\u5f97\u5230\u7d22\u5f15\u4e3a1\u7684\u5143\u7d20\u3002\u8fd9\u662f\u4e00\u79cd\u76f8\u5f53\u5e38\u89c1\u7684\u64cd\u4f5c&#xff0c;\u4e3a\u6b64\u5b58\u5728\u4e00\u79cd\u4e13\u95e8\u7684\u8bed\u6cd5&#xff1a;operator[]\u3002\u5bf9\u4e8e\u6307\u9488\u7c7b\u578b&#xff0c;arr[i] \u4e0e *(arr &#043; i) \u5b8c\u5168\u76f8\u540c\u3002<\/p>\n<p><span class=\"token keyword\">int<\/span><span class=\"token operator\">&amp;<\/span> elem1 <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span>arr <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span><span class=\"token operator\">&amp;<\/span> elem2 <span class=\"token operator\">&#061;<\/span> arr<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ The above two lines are exactly the same.<\/span><br \/>\n<span class=\"token comment\">\/\/ elem1 and elem2 refer to the same element!<\/span><\/p>\n<h5>5.2.4 \u4e0e\u5f15\u7528\u7684\u5173\u7cfb<\/h5>\n<p>\u4e86\u89e3\u6307\u9488\u540e&#xff0c;\u4eba\u4eec\u7ecf\u5e38\u4f1a\u95ee\u6307\u9488\u662f\u5426\u4e0e\u5f15\u7528\u6709\u5173\u3002\u7b54\u6848\u662f\u80af\u5b9a\u7684&#xff01;\u5728\u5e95\u5c42&#xff0c;\u7f16\u8bd1\u5668\u5bf9\u5f85\u5f15\u7528\u7684\u65b9\u5f0f\u548c\u5bf9\u5f85\u6307\u9488\u4e00\u6837&#xff0c;\u4e0d\u8fc7&#xff0c;\u5b83\u4eec\u7684\u8bed\u4e49\u6709\u6240\u4e0d\u540c\u3002\u6307\u9488\u4f7f\u7528-&gt;\u6765\u8bbf\u95ee\u5e95\u5c42\u5bf9\u8c61&#xff0c;\u800c\u5f15\u7528\u5219\u4f7f\u7528\u4e0e\u503c\u7c7b\u578b\u76f8\u540c\u7684.\u3002\u4f5c\u4e3a\u503c\u7c7b\u578b\u7684\u8868\u793a\u6cd5&#xff1a;<\/p>\n<p>std<span class=\"token operator\">::<\/span>pair<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">double<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span> p <span class=\"token punctuation\">{<\/span> <span class=\"token number\">2.72<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3.14<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>std<span class=\"token operator\">::<\/span>pair<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">double<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token operator\">*<\/span> ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>p<span class=\"token punctuation\">;<\/span><br \/>\nstd<span class=\"token operator\">::<\/span>pair<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">double<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token operator\">&amp;<\/span> ref <span class=\"token operator\">&#061;<\/span> p<span class=\"token punctuation\">;<\/span><\/p>\n<p>std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> ptr<span class=\"token operator\">-&gt;<\/span>first <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\\\\n&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\nstd<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> ref<span class=\"token punctuation\">.<\/span>first <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\\\\n&#034;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7136\u800c&#xff0c;\u4e00\u4e2a\u91cd\u8981\u7684\u533a\u522b\u662f\u5f15\u7528\u4e0d\u80fd\u88ab\u91cd\u65b0\u7ed1\u5b9a\u3002\u4e00\u65e6\u5f15\u7528\u88ab\u7ed1\u5b9a&#xff08;\u6307\u5411&#xff09;\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u5b83\u5c31\u5fc5\u987b\u59cb\u7ec8\u6307\u5411\u8be5\u5bf9\u8c61\u3002<\/p>\n<p><span class=\"token keyword\">double<\/span> pi <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">3.14<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> e <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2.72<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ We can rebind pointers, changing what data they point to<\/span><br \/>\n<span class=\"token keyword\">double<\/span><span class=\"token operator\">*<\/span> ptr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>pi<span class=\"token punctuation\">;<\/span><br \/>\nptr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>e<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ However, we cannot do the same with references<\/span><br \/>\n<span class=\"token keyword\">double<\/span><span class=\"token operator\">&amp;<\/span> ref <span class=\"token operator\">&#061;<\/span> pi<span class=\"token punctuation\">;<\/span><br \/>\nref <span class=\"token operator\">&#061;<\/span> e<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ This line changed *pi*, not ref!<\/span><\/p>\n<p>\u6700\u540e&#xff0c;\u5f15\u7528\u4e0d\u5141\u8bb8\u662fnullptr\u2014\u2014 \u5b83\u4eec\u5fc5\u987b\u59cb\u7ec8\u6307\u5411\u4e00\u4e2a\u5bf9\u8c61\u3002\u5b58\u5728\u4e00\u4e9b\u4e0d\u89c4\u8303\u7684\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u5f15\u7528\u5b58\u50a8nullptr&#xff0c;\u4f46\u8fd9\u7c7b\u7a0b\u5e8f\u5373\u4fbf\u80fd\u591f\u7f16\u8bd1&#xff0c;\u5728 C&#043;&#043; \u4e2d\u4e5f\u662f\u65e0\u6548\u7684&#xff0c;\u4e14\u53ef\u80fd\u4f1a\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\u3002<\/p>\n<p>\u4ece\u6280\u672f\u4e0a\u8bb2&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u8fd9\u6837\u7684\u4ee3\u7801\u6765\u83b7\u53d6\u7a7a\u5f15\u7528&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span><span class=\"token operator\">&amp;<\/span> null_ref <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">to_ref<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nstd<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> null_ref <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\\\\n&#034;<\/span><span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ This line will crash!<\/span><\/p>\n<p>\u7136\u800c&#xff0c;\u4efb\u4f55\u8bbf\u95eenull_ref\u7684\u5c1d\u8bd5&#xff08;\u8fd9\u4f1a\u5bfc\u81f4\u5bf9\u5e95\u5c42\u6307\u9488\u8fdb\u884c\u89e3\u5f15\u7528&#xff09;\u90fd\u4f1a\u4f7f\u7a0b\u5e8f\u5d29\u6e83&#xff01;<\/p>\n<h5>5.2.5 \u7efc\u5408\u5e94\u7528<\/h5>\n<p>std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">&gt;<\/span> v <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 punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> arr <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>v<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ Copy construction\u62f7\u8d1d\u6784\u9020<\/span><br \/>\narr<span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>                  <span class=\"token comment\">\/\/ Random access\u968f\u673a\u8bbf\u95ee<\/span><br \/>\n<span class=\"token operator\">&#043;&#043;<\/span>arr<span class=\"token punctuation\">;<\/span>                    <span class=\"token comment\">\/\/ Move pointer forward\u6307\u9488\u524d\u79fb<\/span><br \/>\narr<span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">;<\/span>                  <span class=\"token comment\">\/\/ Random access\u968f\u673a\u8bbf\u95ee<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>arr <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token operator\">&amp;<\/span>v<span class=\"token punctuation\">[<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span>         <span class=\"token comment\">\/\/ Pointer comparison\u6307\u9488\u6bd4\u8f83<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f555.1 \u5185\u5b585.1.1 \u6808**\u6808\u7684\u5b58\u50a8****\u6808\u6ea2\u51fa****\u6808\u7684\u5c40\u9650**5.1.2 \u58065.2 \u6307\u94885.2.1 \u6307\u9488\u7c7b\u578b\\\\*\u89e3\u5f15\u7528-&gt;\u89e3\u5f15\u7528\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458const\u4e0e\u6307\u9488nullptr5.2.2 \u6307\u5411\u5806\u7684\u6307\u9488newdeletenew[] \u548c delete[]5.2.3 \u6307\u9488\u8fd0\u7b975.2.4 \u4e0e\u5f15\u7528\u7684\u5173\u7cfb5.2.5 \u7efc\u5408\u5e94\u75285.1 \u5185\u5b58<br \/>\n\u5728\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00\u4e2d&#xff0c;\u4f60\u521b\u5efa\u7684\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5b58\u5728\u4e8e\u7a0b\u5e8f\u5185\u5b58\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002\u5f53\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\u65f6&#xff0c;\u5b83\u4f1a\u7ed9\u6bcf\u4e2a\u7a0b\u5e8f&#xff08;\u66f4<\/p>\n","protected":false},"author":2,"featured_media":73382,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,371,305],"topic":[],"class_list":["post-73398","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-371","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488 - \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\/73398.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f555.1 \u5185\u5b585.1.1 \u6808**\u6808\u7684\u5b58\u50a8****\u6808\u6ea2\u51fa****\u6808\u7684\u5c40\u9650**5.1.2 \u58065.2 \u6307\u94885.2.1 \u6307\u9488\u7c7b\u578b\\*\u89e3\u5f15\u7528-&gt;\u89e3\u5f15\u7528\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458const\u4e0e\u6307\u9488nullptr5.2.2 \u6307\u5411\u5806\u7684\u6307\u9488newdeletenew[] \u548c delete[]5.2.3 \u6307\u9488\u8fd0\u7b975.2.4 \u4e0e\u5f15\u7528\u7684\u5173\u7cfb5.2.5 \u7efc\u5408\u5e94\u75285.1 \u5185\u5b58 \u5728\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00\u4e2d&#xff0c;\u4f60\u521b\u5efa\u7684\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5b58\u5728\u4e8e\u7a0b\u5e8f\u5185\u5b58\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002\u5f53\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\u65f6&#xff0c;\u5b83\u4f1a\u7ed9\u6bcf\u4e2a\u7a0b\u5e8f&#xff08;\u66f4\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/73398.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-07T07:36:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5e22aba.png\" \/>\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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73398.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/73398.html\",\"name\":\"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-07T07:36:01+00:00\",\"dateModified\":\"2026-02-07T07:36:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/73398.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/73398.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73398.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488\"}]},{\"@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":"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488 - \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\/73398.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f555.1 \u5185\u5b585.1.1 \u6808**\u6808\u7684\u5b58\u50a8****\u6808\u6ea2\u51fa****\u6808\u7684\u5c40\u9650**5.1.2 \u58065.2 \u6307\u94885.2.1 \u6307\u9488\u7c7b\u578b\\*\u89e3\u5f15\u7528-&gt;\u89e3\u5f15\u7528\u8bbf\u95ee\u7ed3\u6784\u4f53\u6210\u5458const\u4e0e\u6307\u9488nullptr5.2.2 \u6307\u5411\u5806\u7684\u6307\u9488newdeletenew[] \u548c delete[]5.2.3 \u6307\u9488\u8fd0\u7b975.2.4 \u4e0e\u5f15\u7528\u7684\u5173\u7cfb5.2.5 \u7efc\u5408\u5e94\u75285.1 \u5185\u5b58 \u5728\u4efb\u4f55\u7f16\u7a0b\u8bed\u8a00\u4e2d&#xff0c;\u4f60\u521b\u5efa\u7684\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5b58\u5728\u4e8e\u7a0b\u5e8f\u5185\u5b58\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002\u5f53\u64cd\u4f5c\u7cfb\u7edf\u542f\u52a8\u65f6&#xff0c;\u5b83\u4f1a\u7ed9\u6bcf\u4e2a\u7a0b\u5e8f&#xff08;\u66f4","og_url":"https:\/\/www.wsisp.com\/helps\/73398.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-07T07:36:01+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207073558-6986eb5e22aba.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/73398.html","url":"https:\/\/www.wsisp.com\/helps\/73398.html","name":"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-07T07:36:01+00:00","dateModified":"2026-02-07T07:36:01+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/73398.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/73398.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/73398.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u57fa\u7840\uff1aStanford CS106L\u5b66\u4e60\u7b14\u8bb0 5 \u5185\u5b58\u4e0e\u6307\u9488"}]},{"@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\/73398","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=73398"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/73398\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/73382"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=73398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=73398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=73398"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=73398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}