{"id":103,"date":"2026-03-18T16:28:31","date_gmt":"2026-03-18T08:28:31","guid":{"rendered":"https:\/\/www.caldm.cn\/?p=103"},"modified":"2026-03-18T20:21:19","modified_gmt":"2026-03-18T12:21:19","slug":"c9-%e6%95%b0%e7%bb%84%e5%92%8c%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"https:\/\/www.caldm.cn\/index.php\/2026\/03\/18\/c9-%e6%95%b0%e7%bb%84%e5%92%8c%e6%8c%87%e9%92%88\/","title":{"rendered":"C9 \u6570\u7ec4\u548c\u6307\u9488"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u6570\u7ec4<\/h2>\n\n\n\n<p>\u6570\u7ec4\u7531\u4e00\u7cfb\u5217\u7c7b\u578b\u76f8\u540c\u7684\u5143\u7d20\u7ec4\u6210\u3002\u4f7f\u7528\u6570\u7ec4\u65f6\uff0c\u9700\u8981\u901a\u8fc7\u58f0\u660e\u6570\u7ec4\u544a\u8bc9\u7f16\u8bd1\u5668\u6570\u636e\u7c7b\u578b\u548c\u5143\u7d20\u6570\u91cf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int scores&#91;5];\nfloat temperatures&#91;7];\n<\/code><\/pre>\n\n\n\n<p>\u58f0\u660e\u6570\u7ec4\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u6807\uff08\u4e5f\u79f0\u7d22\u5f15\uff09\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5404\u4e2a\u5143\u7d20\u3002\u6570\u7ec4\u4e0b\u6807\u4ece0\u5f00\u59cb\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u521d\u59cb\u5316\u6570\u7ec4<\/h3>\n\n\n\n<p>\u521d\u59cb\u5316\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u82b1\u62ec\u53f7\u5217\u8868\u5bf9\u5176\u5404\u4e2a\u5143\u7d20\u8fdb\u884c\u8d4b\u503c\u3002\u82e5\u5217\u8868\u9879\u6570\u5c0f\u4e8e\u6570\u7ec4\u957f\u5ea6\uff0c\u5219\u672a\u521d\u59cb\u5316\u7684\u5143\u7d20\u88ab\u8bbe\u7f6e\u4e3a0\u3002\u82e5\u5217\u8868\u9879\u6570\u5927\u4e8e\u6570\u7ec4\u957f\u5ea6\uff0c\u5219\u7f16\u8bd1\u5668\u4f1a\u62a5\u544a\u9519\u8bef\u3002\u82e5\u7701\u7565\u65b9\u62ec\u53f7\u4e2d\u7684\u6570\u7ec4\uff0c\u5219\u6570\u7ec4\u4f1a\u81ea\u52a8\u5339\u914d\u6570\u7ec4\u5927\u5c0f\u548c\u521d\u59cb\u5316\u5217\u8868\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a1&#91;3] = {1, 2, 3}; \/\/ &#91;1, 2, 3]\nint a2&#91;4] = {1, 2}; \/\/ &#91;1, 2, 0, 0]\nint a3&#91;4] = {1, &#91;2] = 3, 2}; \/\/ &#91;1, 0, 3, 2]\nint a4&#91;4] = {1, 2, 3, &#91;0] = 4}; \/\/ &#91;4, 2, 3, 0]\nint a5&#91;] = {1, 2, 3, 4, 5}; \/\/ \u7b49\u540c\u4e8e a5&#91;5] = {1, 2, 3, 4, 5};\nint a6&#91;] = {1, &#91;10] = 3}; \/\/ \u7b49\u540c\u4e8e a6&#91;11] = {1, &#91;10] = 3};\n<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a<code>sizeof days<\/code>\u662f\u6574\u4e2a\u6570\u7ec4\u7684\u5927\u5c0f\uff0c<code>sizeof(day[0])<\/code>\u662f\u5355\u4e2a\u5143\u7d20\u7684\u5927\u5c0f\uff0c\u4e24\u4e2a\u503c\u76f8\u9664\u53ef\u4ee5\u5f97\u5230\u6570\u7ec4\u5143\u7d20\u7684\u4e2a\u6570\u3002<\/p>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a\u5f53\u6570\u7ec4\u540d\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570\u65f6\u3002\u5728\u51fd\u6570\u5185\u90e8\u6570\u7ec4\u5f62\u53c2\u4f1a\u9000\u5316\u4e3a\u6307\u5411\u5176\u9996\u5143\u7d20\u7684\u6307\u9488\uff0c\u6b64\u65f6<code>sizeof<\/code>\u8fd4\u56de\u7684\u662f\u6307\u9488\u53d8\u91cf\u7684\u5927\u5c0f\uff0c\u800c\u4e0d\u662f\u6574\u4e2a\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u6b64\u65f6\u518d\u7528<code>sizeof<\/code>\u6765\u8ba1\u7b97\u6570\u7ec4\u957f\u5ea6\u5c31\u4f1a\u51fa\u9519\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 \u6307\u5b9a\u521d\u59cb\u5316\u5668<\/h3>\n\n\n\n<p>\u4e0a\u9762\u7684\u521d\u59cb\u5316\u662f\u6309\u987a\u5e8f\u521d\u59cb\u5316\u7684\uff0c\u5982\u679c\u60f3\u8981\u521d\u59cb\u5316\u6307\u5b9a\u7684\u51e0\u4e2a\u5143\u7d20\uff0c\u5e94\u5f53\u4f7f\u7528<strong>\u6307\u5b9a\u521d\u59cb\u5316\u5668<\/strong>\uff08<em>designed initializer<\/em>\uff0cC99\u65b0\u589e\uff09\u3002\u5728\u51fa\u573a\u7ebf\u5217\u8868\u4e2d\u4f7f\u7528\u5e26\u65b9\u62ec\u53f7\u7684\u4e0b\u6807\u6307\u660e\u5f85\u521d\u59cb\u5316\u7684\u5143\u7d20\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a&#91;5] = {1, 2, 3, &#91;4] = 5};\n\/\/ \u521d\u59cb\u5316\u540e\u7684\u6570\u7ec4\u5185\u5bb9\u4e3a\uff1a&#91;1, 2, 3, 0, 5]\n<\/code><\/pre>\n\n\n\n<p>\u5f53\u521d\u59cb\u5316\u5217\u8868\u4e0e\u6307\u5b9a\u521d\u59cb\u5316\u5668\u6df7\u7528\u65f6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int days&#91;12] = {31, 28, &#91;4] = 31, 30, 31, &#91;1] = 29};\n\/\/ \u521d\u59cb\u5316\u540e\u7684\u6570\u7ec4\u5185\u5bb9\u4e3a\uff1a&#91;31, 29, 0, 0, 31, 30, 31, 0, 0, 0, 0, 0 ]\n<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u6307\u5b9a\u521d\u59cb\u5316\u5668\u540e\u6709\u66f4\u591a\u7684\u503c\uff0c\u90a3\u4e48\u8fd9\u4e9b\u503c\u4f1a\u88ab\u7528\u4e8e\u521d\u59cb\u5316\u6307\u5b9a\u5143\u7d20\u540e\u8fb9<\/li>\n\n\n\n<li>\u5982\u679c\u6709\u591a\u6b21\u521d\u59cb\u5316\uff0c\u5219\u540e\u521d\u59cb\u5316\u4f1a\u8986\u76d6\u524d\u521d\u59cb\u5316<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 \u7ed9\u6570\u7ec4\u5143\u7d20\u8d4b\u503c<\/h3>\n\n\n\n<p>\u58f0\u660e\u6570\u7ec4\u540e\u53ef\u4f7f\u7528\u6570\u7ec4\u4e0b\u6807\uff08\u6216\u7d22\u5f15\uff09\u7ed9\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int arr&#91;5];\narr&#91;2] = 100;\narr&#91;4] = 999;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1.4 \u6570\u7ec4\u8fb9\u754c<\/h3>\n\n\n\n<p>C\u4e0d\u4f1a\u68c0\u67e5\u6570\u7ec4\u4e0b\u6807\u662f\u5426\u8d85\u51fa\u6570\u7ec4\u8fb9\u754c\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u8fb9\u754c\u4e4b\u5916\u7684\u4e0b\u6807\uff0c\u4f46\u8bbf\u95ee\u7684\u7ed3\u679c\u662f\u672a\u77e5\u7684\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.5 \u6307\u5b9a\u6570\u7ec4\u5927\u5c0f<\/h3>\n\n\n\n<p>\u5728C99\u6807\u51c6\u4e4b\u524d\uff0c\u58f0\u660e\u6570\u7ec4\u53ea\u80fd\u5728\u65b9\u62ec\u53f7\u4e2d\u4f7f\u7528\u6574\u578b\u5e38\u91cf\u8868\u8fbe\u5f0f\u4e14\u503c\u4e0d\u8bb8\u5927\u4e8e0\u3002<\/p>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a<code>sizeof<\/code>\u8868\u8fbe\u5f0f\u88ab\u89c6\u4e3a\u6574\u578b\u5e38\u91cf\uff0c\u4f46<code>const<\/code>\u503c\u4e0d\u662f\uff08\u4e0eC++\u4e0d\u540c\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u591a\u7ef4\u6570\u7ec4<\/h2>\n\n\n\n<p>\u58f0\u660e\u591a\u7ef4\u6570\u7ec4\u9700\u8981\u4f7f\u7528\u591a\u4e2a\u65b9\u62ec\u53f7\uff0c\u6709\u51e0\u4e2a\u7ef4\u5ea6\u5c31\u9700\u8981\u51e0\u4e2a\u65b9\u62ec\u53f7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a&#91;3]&#91;4];\ndouble b&#91;2]&#91;5]&#91;6];\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u521d\u59cb\u5316\u4e8c\u7ef4\u6570\u7ec4<\/h3>\n\n\n\n<p>\u521d\u59cb\u5316\u4e8c\u7ef4\u6570\u7ec4\u662f\u5efa\u7acb\u5728\u521d\u59cb\u5316\u4e00\u7ef4\u6570\u7ec4\u7684\u57fa\u7840\u4e0a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int ar1&#91;4] = {1, 2, 3, 4};\n\nint arr&#91;3]&#91;4] = {\n    {1, 2, 3, 4}, \n    {5, 6, 7, 8}, \n    {9, 10, 11, 12}\n}\n<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u521d\u59cb\u5316\u4e2d\u4f7f\u75283\u4e2a\u6570\u503c\u5217\u8868\uff0c\u6bcf\u4e2a\u6570\u503c\u5217\u8868\u7528\u4e00\u5bf9\u82b1\u62ec\u53f7\uff0c\u6bcf\u4e00\u884c\u7684\u521d\u59cb\u5316\u4e0e\u521d\u59cb\u5316\u4e00\u7ef4\u6570\u7ec4\u65f6\u76f8\u540c\uff0c\u82e5\u6570\u503c\u6570\u91cf\u5c0f\u4e8e\u6570\u7ec4\u957f\u5ea6\uff0c\u5219\u672a\u521d\u59cb\u5316\u7684\u88ab\u8bbe\u7f6e\u4e3a0\uff0c\u82e5\u6570\u503c\u6570\u91cf\u957f\u5ea6\u5927\u4e8e\u6570\u7ec4\u957f\u5ea6\uff0c\u5219\u4f1a\u62a5\u9519\uff0c\u4f46\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u884c\u7684\u521d\u59cb\u5316\u3002<\/p>\n\n\n\n<p>\u521d\u59cb\u5316\u65f6\u53ef\u4ee5\u7701\u7565\u5185\u90e8\u7684\u82b1\u62ec\u53f7\uff0c\u53ea\u4fdd\u7559\u5916\u90e8\u7684\u82b1\u62ec\u53f7\uff0c\u4f46\u6b64\u65f6\u5c31\u9700\u8981\u6ce8\u610f\u6570\u503c\u7684\u987a\u5e8f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int arr1&#91;3]&#91;4] = {\n    {1, 2, 3, 4}, {5, 6}, {9, 10, 11, 12}\n};\n\/\/\u521d\u59cb\u5316\u7ed3\u679c\uff1a1, 2, 3, 4, 5, 6, 0, 0, 9, 10, 11, 12\nint arr2&#91;3]&#91;4] = {\n    1, 2, 3, 4, 5, 6, 9, 10, 11, 12\n};\n\/\/\u521d\u59cb\u5316\u7ed3\u679c\uff1a1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 0, 0\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u6307\u9488\u548c\u6570\u7ec4<\/h2>\n\n\n\n<p>\u6570\u7ec4\u8868\u793a\u6cd5\u662f\u53d8\u76f8\u5730\u4f7f\u7528\u6307\u9488\u3002\u6570\u7ec4\u540d\u5c31\u662f\u6570\u7ec4\u9996\u5143\u7d20\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a&#91;3] = {};\na == &amp;a&#91;0];\n<\/code><\/pre>\n\n\n\n<p>\u5728\u6211\u4eec\u7684\u7cfb\u7edf\u4e2d\uff0c\u5730\u5740\u6309\u5b57\u8282\u7f16\u5740\uff0c\u7528\u4e00\u4e32\u5341\u516d\u8fdb\u5236\u6570\u5b57\u8868\u793a\uff0c<code>int<\/code>\u7c7b\u578b\u53604\u5b57\u8282\uff0c<code>double<\/code>\u53608\u5b57\u8282\u3002\u5f53<code>int<\/code>\u7c7b\u578b\u7684\u6307\u9488\u548c<code>double<\/code>\u7c7b\u578b\u7684\u6307\u9488\u5206\u522b+1\u65f6\uff0c<code>int<\/code>\u7c7b\u578b\u7684\u5730\u5740\u6570\u5b57\u4f1a+4\uff0c<code>double<\/code>\u7c7b\u578b\u7684\u5730\u5740\u6570\u5b57\u4f1a+8\u3002\u5bf9\u6307\u9488\u800c\u8a00\uff0c+1\u6307\u7684\u662f\u589e\u52a0\u4e00\u4e2a\u50a8\u5b58\u5355\u5143\uff0c\u800c\u4e0d\u662f\u5b57\u8282\u6570+1\u3002\u5bf9\u6570\u7ec4\u800c\u8a00\uff0c+1\u662f\u6307\u5411\u4e0b\u4e00\u4e2a\u5143\u7d20\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u6307\u9488\u53d8\u91cf\u7684\u57fa\u672c\u64cd\u4f5c<\/h3>\n\n\n\n<p>\u8d4b\u503c\u3001\u89e3\u5f15\u7528\u3001\u6c42\u89e3\u3001\u4e0e\u6574\u6570\u76f8\u52a0\u3001\u4e0e\u6574\u6570\u76f8\u51cf\u3001\u9012\u589e\u3001\u9012\u51cf\u3001\u6307\u9488\u6c42\u5dee\u3001\u6307\u9488\u6bd4\u8f83<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nint main() {\n    int arr&#91;5] = {10, 20, 30, 40, 50};\n    int *ptr1 = &amp;arr&#91;1]; \/\/ \u8d4b\u503c\uff1aptr1\u6307\u5411arr&#91;1]\n    int *ptr2 = &amp;arr&#91;3]; \/\/ \u8d4b\u503c\uff1aptr2\u6307\u5411arr&#91;3]\n    \n    \/\/ \u89e3\u5f15\u7528\n    printf(\"*ptr1 = %d\\n\", *ptr1); \/\/ \u8f93\u51fa: 20\n    \n    \/\/ \u53d6\u5730\u5740\n    printf(\"&amp;arr&#91;1] = %p, ptr1 = %p\\n\", &amp;arr&#91;1], ptr1);\n    \n    \/\/ \u4e0e\u6574\u6570\u76f8\u52a0\n    ptr1 = ptr1 + 2; \/\/ ptr1\u73b0\u5728\u6307\u5411arr&#91;3]\n    printf(\"After +2: *ptr1 = %d\\n\", *ptr1); \/\/ \u8f93\u51fa: 40\n    \n    \/\/ \u4e0e\u6574\u6570\u76f8\u51cf\n    ptr1 = ptr1 - 1; \/\/ ptr1\u73b0\u5728\u6307\u5411arr&#91;2]\n    printf(\"After -1: *ptr1 = %d\\n\", *ptr1); \/\/ \u8f93\u51fa: 30\n    \n    \/\/ \u9012\u589e\n    ptr1++; \/\/ ptr1\u73b0\u5728\u6307\u5411arr&#91;3]\n    printf(\"After ++: *ptr1 = %d\\n\", *ptr1); \/\/ \u8f93\u51fa: 40\n    \n    \/\/ \u9012\u51cf\n    ptr1--; \/\/ ptr1\u73b0\u5728\u6307\u5411arr&#91;2]\n    printf(\"After --: *ptr1 = %d\\n\", *ptr1); \/\/ \u8f93\u51fa: 30\n    \n    \/\/ \u6307\u9488\u6c42\u5dee\n    ptrdiff_t diff = ptr2 - ptr1; \/\/ ptr2\u6307\u5411arr&#91;3], ptr1\u6307\u5411arr&#91;2]\n    printf(\"ptr2 - ptr1 = %td\\n\", diff); \/\/ \u8f93\u51fa: 1\n    \n    \/\/ \u6307\u9488\u6bd4\u8f83\n    if (ptr1 &lt; ptr2) {\n        printf(\"ptr1 points to an element before ptr2\\n\");\n    }\n    \n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u51fd\u6570\u3001\u6307\u9488\u548c\u6570\u7ec4<\/h2>\n\n\n\n<p>ANSI C\u89c4\u5b9a\uff0c\u5bf9\u5f62\u5f0f\u53c2\u6570\u4f7f\u7528<code>const<\/code>\u4fee\u9970\u6570\u7ec4\uff0c\u5e76\u4e0d\u8981\u6c42\u6570\u7ec4\u65f6\u5e38\u91cf\uff0c\u800c\u662f\u5728\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u5c06\u5176\u5f53\u505a\u662f\u5e38\u91cf\u6765\u770b\u5f85\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u65e0\u6cd5\u901a\u8fc7\u6307\u9488\u6765\u4fee\u6539\u6570\u7ec4\u7684\u503c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.1 \u4f7f\u7528<code>const<\/code>\u4fee\u9970\u6307\u9488<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int a&#91;3] = {1, 2, 3};\nconst int* p1 = &amp;a&#91;0];       \/\/ \u6307\u5411 const \u7684\u6307\u9488\nint* const p2 = &amp;a&#91;1];       \/\/ const \u6307\u9488\nconst int* const p3 = &amp;a&#91;2]; \/\/ \u65e2\u662f const \u6307\u9488\uff0c\u53c8\u662f\u6307\u5411 const \u7684\u6307\u9488\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e<code>p1<\/code>\uff0c\u4e0d\u53ef\u4ee5\u4fee\u6539\u6307\u9488\u6307\u5411\u7684\u503c\uff0c\u4f46\u53ef\u4ee5\u4fee\u6539\u6307\u9488\u6307\u5411\u7684\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e<code>p2<\/code>\uff0c\u53ef\u4ee5\u4fee\u6539\u6307\u9488\u6307\u5411\u7684\u503c\uff0c\u4f46\u4e0d\u53ef\u4ee5\u4fee\u6539\u6307\u9488\u6307\u5411\u7684\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e<code>p3<\/code>\uff0c\u4e0d\u53ef\u4ee5\u4fee\u6539\u6307\u9488\u6307\u5411\u7684\u503c\uff0c\u4e5f\u4e0d\u53ef\u4ee5\u4fee\u6539\u6307\u9488\u6307\u5411\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.1.1 <code>const<\/code>\u7684\u5176\u4ed6\u5185\u5bb9<\/h4>\n\n\n\n<p>\u5173\u4e8e\u6307\u9488\u8d4b\u503c\u548c<code>const<\/code>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u628a<code>const<\/code>\u6570\u636e\u6216\u975e<code>const<\/code>\u6570\u636e\u7684\u5730\u5740\u521d\u59cb\u5316\u4e3a<code>const<\/code>\u6307\u9488\u662f\u5408\u6cd5\u7684\u3002<\/li>\n\n\n\n<li>\u53ea\u80fd\u628a\u975e<code>const<\/code>\u6570\u636e\u7684\u5730\u5740\u8d4b\u7ed9\u666e\u901a\u6307\u9488\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1aC\u6807\u51c6\u89c4\u5b9a\uff0c\u4f7f\u7528\u975e<code>const<\/code>\u6807\u8bc6\u7b26\u7684\u5f62\u53c2\u4fee\u6539<code>const<\/code>\u6570\u636e\uff0c\u5bfc\u81f4\u7684\u7ed3\u679c\u662f\u672a\u5b9a\u4e49\u7684\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.2 \u6307\u9488\u8868\u793a\u6cd5\u548c\u6570\u7ec4\u8868\u793a\u6cd5<\/h3>\n\n\n\n<p>\u6570\u7ec4\u540d\u662f\u6307\u5411\u6570\u7ec4\u9996\u5143\u7d20\u7684\u6307\u9488\u3002\u5bf9\u4e8eC\u8bed\u8a00\uff0c<code>ar[i]<\/code>\u548c<code>*(ar+i)<\/code>\u662f\u7b49\u4ef7\u7684\uff0c\u4f46\u662f\u53ea\u6709<code>ar<\/code>\u662f\u6307\u9488\u53d8\u91cf\u65f6\uff0c\u624d\u80fd\u4f7f\u7528\u9012\u589e\u6216\u9012\u51cf\u3002<\/p>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a\u4e3a\u4ec0\u4e48<code>ar<\/code>\u662f\u6570\u7ec4\u540d\u65f6\u4e0d\u80fd\u4f7f\u7528\u9012\u589e\u6216\u9012\u51cf\uff1f<\/p>\n\n\n\n<p>\u6570\u7ec4\u540d\u662f\u5e38\u91cf\u6307\u9488\uff0c\u4e0d\u662f\u6307\u9488\u53d8\u91cf\uff0c\u4f7f\u7528\u9012\u589e\u6216\u9012\u51cf\u65f6\u4f1a\u5bf9\u5176\u8fdb\u884c\u8d4b\u503c\uff0c\u8fd9\u662f\u4e0d\u5141\u8bb8\u7684\u3002\u5982\u679c\u5141\u8bb8\u5bf9\u6570\u7ec4\u540d\u4f7f\u7528\u9012\u589e\u6216\u9012\u51cf\u7684\u8bdd\uff0c\u90a3\u4e48\u4e00\u4e2a\u6570\u7ec4\u540d\u5c31\u65e0\u6cd5\u4fdd\u8bc1\u5b83\u6307\u5411\u7684\u662f\u6570\u7ec4\u9996\u5143\u7d20\uff0c\u56e0\u4e3a\u5b83\u53ef\u80fd\u88ab\u4fee\u6539\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u6307\u9488\u548c\u591a\u7ef4\u6570\u7ec4<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>int arr&#91;4]&#91;2];\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>arr<\/code>\u662f\u6570\u7ec4\u9996\u5143\u7d20\u7684\u5730\u5740\uff0c\u5b83\u4e0e<code>&amp;arr[0]<\/code>\u7684\u503c\u76f8\u540c\uff0c\u4f46\u542b\u4e49\u4e0d\u540c\u3002<code>arr<\/code>\u662f\u4e00\u4e2a\u5360\u7528\u4e24\u4e2a<code>int<\/code>\u7c7b\u578b\u5927\u5c0f\u5bf9\u8c61\u7684\u5730\u5740\uff0c<code>&amp;arr[0]<\/code>\u662f\u4e00\u4e2a\u5360\u7528\u4e00\u4e2a<code>int<\/code>\u7c7b\u578b\u5927\u5c0f\u5bf9\u8c61\u5730\u5740\u3002<\/li>\n\n\n\n<li>\u5bf9<code>arr<\/code>\u548c<code>&amp;arr[0]<\/code>+1\u540e\u7684\u503c\u4e0d\u540c\u3002<code>arr<\/code>\u589e\u52a0\u4e24\u4e2a<code>int<\/code>\u5927\u5c0f\uff0c\u800c<code>&amp;a[0]<\/code>\u53ea\u589e\u52a0\u4e00\u4e2a<code>int<\/code>\u5927\u5c0f\u3002<\/li>\n\n\n\n<li>\u89e3\u5f15\u7528\u6216\u5728\u6570\u7ec4\u540d\u540e\u52a0\u65b9\u62ec\u53f7\u7684\u503c\u4e0d\u540c\uff0c\u89e3\u5f15\u7528<code>arr<\/code>\u5f97\u5230\u7684\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a\u4e8c\u7684<code>int<\/code>\u7c7b\u578b\u7684\u6570\u7ec4\u7684\u5730\u5740\uff0c\u89e3\u5f15\u7528<code>&amp;arr[0]<\/code>\u5f97\u5230\u7684\u662f\u5b58\u50a8\u5728\u5bf9\u5e94\u4f4d\u7f6e\u4e0a\u7684\u503c\u3002<code>**arr<\/code>\u624d\u548c<code>*&amp;arr[0][0]<\/code>\u7b49\u4ef7\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5.1 \u6307\u5411\u591a\u7ef4\u6570\u7ec4\u7684\u6307\u9488<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int (* pz)&#91;2]; \/\/ pz\u6307\u5411\u4e00\u4e2a\u5185\u542b\u4e24\u4e2aint\u7c7b\u578b\u7684\u6570\u7ec4\n<\/code><\/pre>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u8981\u52a0\u5706\u62ec\u53f7\uff1f\u56e0\u4e3a\u65b9\u62ec\u53f7\u7684\u4f18\u5148\u7ea7\u6bd4\u661f\u53f7\u9ad8\uff0c\u5982\u679c\u4e0d\u52a0\u5706\u62ec\u53f7\uff0c\u90a3\u4e48<code>int * pz[2]<\/code>\u4f1a\u88ab\u7406\u89e3\u4e3a\u4e00\u4e2a\u957f\u5ea6\u4e3a\u4e8c\u3001\u50a8\u5b58\u6307\u5411int\u7c7b\u578b\u6307\u9488\u7684\u6570\u7ec4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.2 \u6307\u9488\u7684\u517c\u5bb9\u6027<\/h3>\n\n\n\n<p>\u6307\u9488\u4e4b\u95f4\u7684\u8d4b\u503c\u6bd4\u6570\u503c\u7c7b\u578b\u7684\u8d4b\u503c\u8981\u66f4\u52a0\u4e25\u683c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int ar1&#91;2]&#91;3] = {1, 2, 3};\nint** p1;\n<\/code><\/pre>\n\n\n\n<p><code>p1<\/code>\u6307\u5411\u7684\u6307\u9488\u662f\u6307\u5411<code>int<\/code>\u7c7b\u578b\u7684\u6307\u9488\uff0c<code>ar1<\/code>\u662f\u6570\u7ec4\u9996\u5143\u7d20\u7684\u6307\u9488\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>**ar1;\/\/\u7ed3\u679c\uff1a1\n<\/code><\/pre>\n\n\n\n<p>\u867d\u7136\u53ef\u4ee5\u5bf9<code>ar1<\/code>\u8fdb\u884c\u4e24\u6b21\u89e3\u5f15\u7528\uff0c\u4f46\u4e0d\u80fd\u5c06<code>ar1<\/code>\u8d4b\u503c\u7ed9<code>p1<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>p1 = ar1; \/\/ \u62a5\u9519\uff0c\u6307\u5411\u7684\u7c7b\u578b\u4e0d\u76f8\u5173\n<\/code><\/pre>\n\n\n\n<p><code>ar1<\/code>\u662f\u6307\u5411\u6570\u7ec4\u7684\u6307\u9488\uff0c<code>ar1[0]<\/code>\u624d\u662f\u6307\u5411<code>int<\/code>\u7684\u6307\u9488\uff0c\u56e0\u6b64\u53ef\u4ee5\u5c06<code>ar1[0]<\/code>\u8d4b\u503c\u7ed9<code>*p1<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int* ptr; \/\/ \u4ec5\u7528\u4e8e\u7ed9**p1\u521d\u59cb\u5316\nint **p1 = &amp;ptr;\n*p1 = ar1&#91;0];\n<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1aC<code>const<\/code>\u548cC++<code>const<\/code> C\u548cC++\u4e2d<code>const<\/code>\u7684\u7528\u6cd5\u5f88\u76f8\u4f3c\uff0c\u4f46\u5374\u4e0d\u5b8c\u5168\u76f8\u540c\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>C++\u5141\u8bb8\u5728\u58f0\u660e\u6570\u7ec4\u5927\u5c0f\u65f6\u4f7f\u7528<code>const<\/code>\u6574\u6570\uff0c\u800cC\u4e0d\u5141\u8bb8<\/li>\n\n\n\n<li>C++\u4e0d\u5141\u8bb8\u5c06<code>const<\/code>\u6307\u9488\u8d4b\u7ed9\u975e<code>const<\/code>\u6307\u9488\uff0c\u800cC\u5141\u8bb8\uff0c\u4f46\u662f\u4f7f\u7528\u975e<code>const<\/code>\u6307\u9488\u4fee\u6539<code>const<\/code>\u53d8\u91cf\u4f1a\u53d1\u751f\u4ec0\u4e48\u662f\u672a\u5b9a\u4e49\u7684<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">6. \u53d8\u957f\u6570\u7ec4\uff08VLA\uff09<\/h2>\n\n\n\n<p>C\u89c4\u5b9a\u6570\u7ec4\u7684\u7ef4\u6570\u5fc5\u987b\u662f\u5e38\u91cf\uff0c\u4e0d\u80fd\u7528\u53d8\u91cf\u3002C99\u65b0\u589e\u4e86<strong>\u53d8\u957f\u6570\u7ec4<\/strong>\uff08<em>variable-length array, VLA<\/em>\uff09\uff0c\u5141\u8bb8\u4f7f\u7528\u53d8\u91cf\u58f0\u660e\u6570\u7ec4\u7684\u7ef4\u5ea6\u3002<\/p>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1a\u53d8\u957f\u6570\u7ec4\u4e0d\u80fd\u5728\u58f0\u660e\u540e\u6539\u53d8\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u53d8\u957f\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528\u53d8\u91cf\u6765\u58f0\u660e\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.1 \u53d8\u957f\u6570\u7ec4\u7684\u5f62\u53c2\u58f0\u660e<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int sum2d(int rows, int cols, int ar&#91;rows]&#91;cols]);\n<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f<strong>\u6ce8\u610f<\/strong>\uff1aC99\/C11\u6807\u51c6\u89c4\u5b9a\u53ef\u4ee5\u5728\u51fd\u6570\u539f\u578b\u4e2d\u7684\u5f62\u53c2\u540d\uff0c\u4f46\u5fc5\u987b\u7528\u661f\u53f7\u4ee3\u66ff\u7701\u7565\u7684\u7ef4\u5ea6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int sum2d(int, int, int ar&#91;*]&#91;*]);\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">7. \u590d\u5408\u5b57\u9762\u91cf<\/h2>\n\n\n\n<p>\u5b57\u9762\u91cf\uff0c\u7b26\u53f7\u5e38\u91cf\u5916\u7684\u5e38\u91cf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u57fa\u672c\u7c7b\u578b\u7684\u5b57\u9762\u91cf\n5 \/\/ int \u7c7b\u578b\u5b57\u9762\u91cf\n81.3 \/\/ double \u7c7b\u578b\u5b57\u9762\u91cf\n'y' \/\/ char \u7c7b\u578b\u5b57\u9762\u91cf\n\"elephant\" \/\/ \u5b57\u7b26\u4e32\u5b57\u9762\u91cf\n<\/code><\/pre>\n\n\n\n<p>C99\u65b0\u589e\u4e86\u590d\u5408\u5b57\u9762\u91cf\u3002\u5bf9\u4e8e\u6570\u7ec4\uff0c\u590d\u5408\u5b57\u9762\u91cf\u7c7b\u4f3c\u521d\u59cb\u5316\u5217\u8868\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>`int diva&#91;2] = {10, 20};`\n(int &#91;2]) {10, 20};\n<\/code><\/pre>\n\n\n\n<p>\u6570\u7ec4\u7684\u590d\u5408\u5b57\u9762\u91cf\u683c\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(\u7c7b\u578b\u540d) \u521d\u59cb\u5316\u5217\u8868;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \u6570\u7ec4 \u6570\u7ec4\u7531\u4e00\u7cfb\u5217\u7c7b\u578b\u76f8\u540c\u7684\u5143\u7d20\u7ec4\u6210\u3002\u4f7f\u7528\u6570\u7ec4\u65f6\uff0c\u9700\u8981\u901a\u8fc7\u58f0\u660e\u6570\u7ec4\u544a\u8bc9\u7f16\u8bd1\u5668\u6570\u636e\u7c7b\u578b\u548c\u5143\u7d20\u6570\u91cf\u3002 \u58f0\u660e\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[11],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-c-2","tag-c-2"],"_links":{"self":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":3,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":107,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/posts\/103\/revisions\/107"}],"wp:attachment":[{"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.caldm.cn\/index.php\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}