{"id":7925,"date":"2023-01-28T13:45:39","date_gmt":"2023-01-28T05:45:39","guid":{"rendered":"https:\/\/egonlin.com\/?p=7925"},"modified":"2023-01-28T13:45:39","modified_gmt":"2023-01-28T05:45:39","slug":"17-%e5%a4%8d%e5%90%88%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e4%b9%8b%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=7925","title":{"rendered":"17 \u590d\u5408\u6570\u636e\u7c7b\u578b\u4e4b\u6570\u7ec4"},"content":{"rendered":"<h1>\u590d\u5408\u6570\u636e\u7c7b\u578b\u4e4b\u6570\u7ec4Array<\/h1>\n<h2>\u4e00 \u6570\u7ec4\u4ecb\u7ecd<\/h2>\n<p>\u6570\u7ec4\u662f\u4e00\u7ec4<code>\u540c\u4e00\u7c7b\u6570\u636e<\/code>\u7684\u96c6\u5408\uff0c\u6570\u7ec4\u5305\u542b\u7684\u5143\u7d20\u4e2a\u6570\u88ab\u79f0\u4e3a\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u53ef\u7528len(\u6570\u7ec4)\u6765\u7edf\u8ba1\u3002<\/p>\n<p>\u7279\u70b9\u5982\u4e0b<\/p>\n<ul>\n<li>1\u3001\u6570\u7ec4\u5185\u7684\u5143\u7d20\u53ef\u4ee5\u88ab\u6539\u53d8\uff0c\u4f46\u662f\u6570\u7ec4\u7684\u957f\u5ea6\u4e0d\u53ef\u88ab\u6539\u53d8\u3002<\/li>\n<li>2\u3001\u6570\u7ec4\u662f\u91c7\u7528\u7d22\u5f15\u5bf9\u5e94\u5143\u7d20\uff0c\u7d22\u5f15\u4ece0\u5f00\u59cb\uff0c\u5230len(\u6570\u7ec4)-1\u7ed3\u675f\uff0c\u4e0d\u652f\u6301\u8d1f\u5411\u7d22\u5f15<\/li>\n<li>3\u3001\u6570\u7ec4\u662f\u503c\u7c7b\u578b\u3001\u4f20\u9012\u6570\u7ec4\u7684\u5f00\u9500\u6bd4\u8f83\u5927<\/li>\n<\/ul>\n<p>\u6570\u7ec4\u7684\u7279\u70b9\u51b3\u5b9a\u4e86\u5176\u4f7f\u7528\u7684\u5c40\u9650\u6027\uff0c\u56e0\u6b64\u5728Go\u8bed\u8a00\u4e2d\u5f88\u5c11\u76f4\u63a5\u4f7f\u7528\u6570\u7ec4\u3002<\/p>\n<p>\u548c\u6570\u7ec4\u5bf9\u5e94\u7684\u7c7b\u578b\u662fSlice\uff08\u5207\u7247\uff09\uff0c\u5b83\u662f\u53ef\u4ee5\u589e\u957f\u548c\u6536\u7f29\u52a8\u6001\u5e8f\u5217\uff0cslice\u7684\u4f7f\u7528\u66f4\u4e3a\u7075\u6d3b\uff0c\u5e76\u4e14\u5207\u7247\u662f\u5f15\u7528\u7c7b\u578b\u3001\u4f20\u9012\u5f00\u9500\u5c0f\uff0c\u56e0\u6b64\u5207\u7247\u8981\u6bd4\u6570\u7ec4\u66f4\u4e3a\u5e38\u7528\u4e00\u4e9b\uff0c\u4f46\u662f\u8981\u7406\u89e3slice\u5de5\u4f5c\u539f\u7406\u7684\u8bdd\u9700\u8981\u5148\u7406\u89e3\u6570\u7ec4\u3002<\/p>\n<h2>\u4e8c \u58f0\u660e\u4e0e\u521d\u59cb\u5316<\/h2>\n<h3>2.1 \u6570\u7ec4\u7684\u58f0\u660e\u8bed\u6cd5<\/h3>\n<pre><code class=\"language-go\">var \u6570\u7ec4\u53d8\u91cf\u540d [\u5143\u7d20\u6570\u91cf]T  \n\n\/\/ \u4f8b\u5982\u5b9a\u4e49\u4e00\u4e2a\u957f\u5ea6\u4e3a3\u5143\u7d20\u7c7b\u578b\u4e3aint\u7684\u6570\u7ec4a\nvar a [3]int<\/code><\/pre>\n<h3>2.2 \u6570\u7ec4\u7684\u521d\u59cb\u5316<\/h3>\n<ul>\n<li>\n<p>1\u3001\u96f6\u503c\u521d\u59cb\u5316\uff1a\u6570\u7ec4\u662f\u503c\u7c7b\uff0c\u82e5\u58f0\u660e\u65f6\u672a\u521d\u59cb\u5316\u503c\uff0c\u5219\u4f9d\u636e\u5176\u5305\u542b\u7684\u5143\u7d20\u7c7b\u578b\u586b\u5145\u5bf9\u5e94\u96f6\u503c\u3002<\/p>\n<pre><code class=\"language-go\">var a [3]int   \/\/ \u5143\u7d20\u7684\u7c7b\u578b\u4e3aint\uff0c\u96f6\u503c\u662f0\nfmt.Println(a) \/\/ [0 0 0]<\/code><\/pre>\n<\/li>\n<li>\n<p>2\u3001\u6307\u5b9a\u4e00\u7ec4\u503c\u6765\u521d\u59cb\u5316\u6570\u7ec4\uff1a\u503c\u4e2a\u6570\u7b49\u4e8e\u6570\u7ec4\u957f\u5ea6<\/p>\n<pre><code class=\"language-go\">var cityArray = [3]string{\"\u5317\u4eac\", \"\u4e0a\u6d77\", \"\u6df1\u5733\"}  \nfmt.Println(cityArray) \/\/ [\u5317\u4eac \u4e0a\u6d77 \u6df1\u5733]<\/code><\/pre>\n<\/li>\n<li>\n<p>3\u3001\u6307\u5b9a\u4e00\u7ec4\u503c\u6765\u521d\u59cb\u5316\u6570\u7ec4\uff1a\u503c\u4e2a\u6570\u5c0f\u4e8e\u6570\u7ec4\u957f\u5ea6\uff0c\u7f3a\u5931\u7684\u5219\u81ea\u52a8\u586b\u5145\u5bf9\u5e94\u96f6\u503c<\/p>\n<pre><code class=\"language-go\">var numArray [3]int = [3]int{111, 222}  \/\/ \u957f\u5ea6\u4e3a3\uff0c\u521d\u59cb\u5316\u4e86\u524d\u4e24\u4e2a\u503c\uff0c\u7b2c\u4e09\u4e2a\u503c\u7528\u96f6\u503c\u586b\u5145\nfmt.Println(numArray)  \/\/ [111 2222 0]<\/code><\/pre>\n<\/li>\n<li>\n<p>4\u3001\u7528\u201c&#8230;\u201d\u7701\u7565\u53f7\u4ee3\u66ff\u957f\u5ea6\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u4f1a\u6839\u636e\u521d\u59cb\u5316\u503c\u7684\u4e2a\u6570\u63a8\u5bfc\u51fa\u6765<\/p>\n<pre><code class=\"language-go\">var names = [...]string{\"egon\", \"EGON\"}\nfmt.Println(names) \/\/ [egon EGON]\n\nfmt.Println(len(names))  \/\/ 2\nfmt.Printf(\"%T\\n\",names) \/\/ [2]string\n\n\/\/ \u5c0f\u7ec3\u4e60\uff1a\u6307\u5b9a\u7d22\u5f15\ntype Currency int\n\nconst (\n  USD Currency = iota \/\/ \u7f8e\u5143\n  EUR                 \/\/ \u6b27\u5143\n  GBP                 \/\/ \u82f1\u9551\n  RMB                 \/\/ \u4eba\u6c11\u5e01\n)\n\nsymbol := [...]string{USD: \"$\", EUR: \"\u20ac\", GBP: \"\uffe1\", RMB: \"\uffe5\"}\n\nfmt.Println(RMB, symbol[RMB]) \/\/ \"3 \uffe5\"<\/code><\/pre>\n<\/li>\n<li>\n<p>5\u3001\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6307\u5b9a\u7d22\u5f15\u503c\u7684\u65b9\u5f0f\u6765\u521d\u59cb\u5316\u6570\u7ec4\uff0c\u7f3a\u5931\u7684\u5219\u81ea\u52a8\u586b\u5145\u5bf9\u5e94\u96f6\u503c<\/p>\n<pre><code class=\"language-go\">\/\/ \u7d22\u5f15\u5206\u914d\u5230\u4e865\uff0c\u6240\u4ee5\u603b\u5171\u67096\u4e2a\u5143\u7d20\uff0c\u521d\u59cb\u5316\u4e86\u4e24\u4e2a\u5143\u7d20\uff0c\u7f3a\u5931\u7684\u5143\u7d20\u5219\u7528\u96f6\u503c\u521d\u59cb\u5316\nnums := [...]int{1: 111, 5: 222}\nfmt.Println(nums) \/\/ [0 111 0 0 0 222]\nfmt.Printf(\"%T\\n\", nums) \/\/ [6]int<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff1a<\/p>\n<p>1\u3001\u56e0\u4e3a\u6570\u7ec4\u7684\u957f\u5ea6\u9700\u8981\u5728\u7f16\u8bd1\u9636\u6bb5\u786e\u5b9a\uff0c\u6240\u4ee5\u5728\u58f0\u660e\u65f6\u6570\u7ec4\u65f6\uff0c\u6570\u7ec4\u7684\u957f\u5ea6\u5fc5\u987b\u662f\u5e38\u91cf\u6216\u8005\u4e00\u4e2a\u5e38\u91cf\u8868\u8fbe\u5f0f\uff08\u5e38\u91cf\u8868\u8fbe\u5f0f\u662f\u6307\u5728\u7f16\u8bd1\u671f\u5373\u53ef\u8ba1\u7b97\u7ed3\u679c\u7684\u8868\u8fbe\u5f0f\uff09<\/p>\n<p>2\u3001\u4e0d\u80fd\u5f80\u6570\u7ec4\u91cc\u6dfb\u52a0\u6216\u5220\u9664\u503c\uff0c\u6570\u7ec4\u4e00\u65e6\u5b9a\u4e49\uff0c\u957f\u5ea6\u4e0d\u53ef\u6539\u53d8\u3002<\/p>\n<p>3\u3001\u6570\u7ec4\u5c5e\u4e8e\u590d\u5408\u7c7b\u578b\uff0c\u800c\u590d\u5408\u7c7b\u578b\u6240\u5305\u542b\u7684\u5143\u7d20\u4e2a\u6570\uff08\u6216\u79f0\u957f\u5ea6\uff09\uff0c\u8fd8\u6709\u4f4d\u7f6e\uff0c\u90fd\u662f\u7c7b\u578b\u4e00\u90e8\u5206\uff0c\u6240\u4ee5 <code>[3]int<\/code>\u548c<code>[5]int<\/code>\u662f\u4e0d\u540c\u7684\u7c7b\u578b\u3002<\/p>\n<pre><code class=\"language-go\">var a [3]int\nvar b [5]int\na = b \/\/ \u9519\u8bef\uff0c\u56e0\u4e3a\u6b64\u65f6a\u548cb\u662f\u4e0d\u540c\u7684\u7c7b\u578b,<\/code><\/pre>\n<p>4\u3001\u6570\u7ec4\u5d4c\u5957\u6570\u7ec4\u53c8\u79f0\u591a\u7ef4\u6570\u7ec4\uff0c\u591a\u7ef4\u6570\u7ec4<strong>\u53ea\u6709\u7b2c\u4e00\u5c42<\/strong>\u53ef\u4ee5\u4f7f\u7528<code>...<\/code>\u6765\u8ba9\u7f16\u8bd1\u5668\u63a8\u5bfc\u6570\u7ec4\u957f\u5ea6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-go\">\/\/\u652f\u6301\u7684\u5199\u6cd5\na := [...][2]string{\n    {&quot;\u6797\u5927\u725b&quot;, &quot;\u6797\u4e8c\u725b&quot;},\n    {&quot;\u674e\u4e00\u86cb&quot;, &quot;\u674e\u4e8c\u86cb&quot;},\n    {&quot;\u738b\u4e00\u70ae&quot;, &quot;\u738b\u4e09\u70ae&quot;},\n}\n\n\/\/\u4e0d\u652f\u6301\u591a\u7ef4\u6570\u7ec4\u7684\u5185\u5c42\u4f7f\u7528...\nb := [3][...]string{\n    {&quot;\u6797\u5927\u725b&quot;, &quot;\u6797\u4e8c\u725b&quot;},\n    {&quot;\u674e\u4e00\u86cb&quot;, &quot;\u674e\u4e8c\u86cb&quot;},\n    {&quot;\u738b\u4e00\u70ae&quot;, &quot;\u738b\u4e09\u70ae&quot;},\n}<\/code><\/pre>\n<h2>\u4e09 \u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/h2>\n<p>\u4ec5\u9650\u5236\u7528\u540c\u7c7b\u578b\u6570\u7ec4\u4e4b\u95f4\u8fdb\u884c\uff0c\u5373\u6570\u7ec4\u957f\u5ea6\u3001\u5143\u7d20\u7c7b\u578b\u90fd\u5fc5\u987b\u4e00\u6837\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-go\">var x [3]int = [3]int{111,222,333}\nvar y [3]int = [3]int(x)  \/\/ x\u4e0ey\u7684\u957f\u5ea6\u3001\u5143\u7d20\u7c7b\u578b\u90fd\u4e00\u6837<\/code><\/pre>\n<p>\u9519\u8bef\u6848\u4f8b<\/p>\n<pre><code class=\"language-go\">\/\/ \u4f8b1\nvar x []int = []int{111,222,333}\nvar y [3]int = [3]int(x)  \/\/ \u9519\u8bef\n\n\/\/ \u4f8b2\nvar y [3]int32 = [3]int32(&quot;hello&quot;)  \/\/ \u9519\u8bef\n\n\u601d\u8003\uff0c\u4e3a\u4f55\u4e0b\u9762\u7684\u8f6c\u6362\u5c31\u53ef\u4ee5\nvar y []int32 = []int32(&quot;hello&quot;)\nfmt.Println(y)  \/\/ [104 101 108 108 111] <\/code><\/pre>\n<h2>\u56db \u57fa\u672c\u64cd\u4f5c<\/h2>\n<h3>4.1 \u589e\u5220\u6539\u67e5<\/h3>\n<p>\u6570\u7ec4\u957f\u5ea6\u4e0d\u53ef\u53d8\uff0c\u6240\u4ee5\u65e0\u6cd5\u4e0d\u80fd\u589e\u3001\u5220\uff0c\u53ea\u80fd\u6539\u3001\u67e5\uff0c\u7d22\u5f15\u5fc5\u987b\u662f\u975e\u8d1f\u6570<\/p>\n<pre><code class=\"language-go\">var cityArray = [3]string{&quot;\u5317\u4eac&quot;, &quot;\u4e0a\u6d77&quot;, &quot;\u6df1\u5733&quot;}\n\n\/\/ \u67e5\u8be2\uff1a\nfmt.Println(cityArray[0])        \/\/ \u5317\u4eac\nfmt.Println(cityArray[len(cityArray)-1]) \/\/ \u6df1\u5733\nfmt.Println(cityArray[-1]) \/\/ \u9519\u8bef\uff0c\u7d22\u5f15\u5fc5\u987b\u662f\u975e\u8d1f\u7684\n\n\/\/ \u4fee\u6539\ncityArray[1] = &quot;\u9b54\u90fd&quot;\nfmt.Println(cityArray)  \/\/ [\u5317\u4eac \u9b54\u90fd \u6df1\u5733]\ncityArray[666] = &quot;\u9b54\u90fd&quot;  \/\/ \u7d22\u5f15\u4e0d\u5b58\u5728\u5219\u62a5\u9519<\/code><\/pre>\n<h3>4.2 \u4e8c\u5143\u8fd0\u7b97<\/h3>\n<p>\uff081\uff09\u6570\u7ec4\u5c5e\u4e8e\u590d\u5408\u7c7b\u578b\u4e2d\u7684\u503c\u7c7b\u578b\uff0c\u590d\u5408\u7c7b\u578b\u4e2d\u7684\u503c\u7c7b\u578b\u652f\u6301\u8fdb\u884c\u76f8\u7b49\u6027\u5224\u65ad\uff0c\u4f46\u5fc5\u5907\u4e24\u4e2a\u6761\u4ef6<\/p>\n<p>\u200b   I.\u5f85\u6bd4\u8f83\u7684\u4e24\u4e2a\u6570\u7ec4\u672c\u8eab\uff0c\u5fc5\u987b\u662f\u76f8\u540c\u7684\u7c7b\u578b<\/p>\n<p>\u200b   II:\u5f85\u6bd4\u8f83\u7684\u4e24\u4e2a\u6570\u7ec4\u4e2d\uff0c\u5bf9\u5e94\u7684\u5143\u7d20\u90fd\u662f\u53ef\u8fdb\u884c\u76f8\u7b49\u6027\u5224\u65ad\u7684<\/p>\n<pre><code class=\"language-go\">\/\/ \u4f8b1\uff1a\na := [2]int{1, 2}\nb := [...]int{1, 2}\nc := [2]int{1, 3}\nfmt.Println(a == b, a == c, b == c) \/\/ \u7f16\u8bd1\u901a\u8fc7\uff0c\u8f93\u51fa\uff1a&quot;true false false&quot;\n\n\/\/ \u4f8b2\uff1a\na := [2]int{1, 2}\nd := [3]int{1, 2}\nfmt.Println(a == d) \/\/ \u7f16\u8bd1\u5931\u8d25: cannot compare [2]int == [3]int\n\n\/\/ \u4f8b3\uff1a\u5982\u4e0bm\u4e0en\u662f\u540c\u7c7b\u578b\uff0c\u4f46\u5185\u90e8\u5143\u7d20\u662f\u5207\u7247\uff0c\u5207\u7247\u662f\u4e0d\u80fd\u6bd4\u8f83\u7684\nvar m [2][]int = [2][]int{\n    {111, 222},\n    {333, 444},\n}\n\nvar n [2][]int = [2][]int{\n    {111, 222},\n    {333, 444},\n}\n\nfmt.Println(m) \/\/ [[111 222] [333 444]]\nfmt.Println(n) \/\/ [[111 222] [333 444]]\n\nfmt.Println(m == n) \/\/ \u62a5\u9519\uff1a[2][]int cannot be compared<\/code><\/pre>\n<p>\uff082\uff09\u6570\u7ec4\u4e0d\u53ef\u4ee5\u6bd4\u5927\u5c0f\uff0c\u82e5\u60f3\u6bd4\u8f83\uff0c\u53ef\u4ee5\u7f16\u5199\u51fd\u6570\u4f9d\u6b21\u53d6\u51fa\u5143\u7d20\u8fdb\u884c\u6bd4\u8f83\uff0c\u5c31\u50cf\u5b57\u7b26\u4e32\u6bd4\u5927\u5c0f\u7684\u5e95\u5c42\u539f\u7406\u4e00\u6837<\/p>\n<h3>4.3 \u904d\u5386\u6570\u7ec4\u5143\u7d20<\/h3>\n<p>\u904d\u5386\u4e00\u7ef4\u6570\u7ec4<\/p>\n<pre><code class=\"language-go\">cityArray := [...]string{&quot;\u5317\u4eac&quot;, &quot;\u4e0a\u6d77&quot;, &quot;\u6df1\u5733&quot;}\n\n\/\/ \u904d\u5386\u6570\u7ec4\u5143\u7d20\u7684\u65b9\u6cd51\uff1a\u57fa\u4e8e\u7d22\u5f15\nfor i := 0; i &lt; len(cityArray); i++ {\n    fmt.Println(cityArray[i])\n}\n\n\/\/ \u904d\u5386\u6570\u7ec4\u5143\u7d20\u7684\u65b9\u6cd52\uff1a\u57fa\u4e8erange\nfor index, value := range cityArray {\n    fmt.Println(index, value)\n}<\/code><\/pre>\n<p>\u904d\u5386\u591a\u7ef4\u6570\u7ec4<\/p>\n<pre><code class=\"language-go\">\/\/ \u904d\u5386\u4e8c\u7ef4\u6570\u7ec4\uff1a\u5982\u4e0b3\u884c2\u5217\na := [3][2]string{\n    {&quot;\u6797\u5927\u725b&quot;, &quot;\u6797\u4e8c\u725b&quot;},\n    {&quot;\u674e\u4e00\u86cb&quot;, &quot;\u674e\u4e8c\u86cb&quot;},\n    {&quot;\u738b\u4e00\u70ae&quot;, &quot;\u738b\u4e09\u70ae&quot;},\n}\n\nfor _,v1:=range  a{\n    for _,v2:=range v1{\n        fmt.Println(v2)\n    }\n}\n\n\u200b```\n\u8f93\u51fa\uff1a\n\u6797\u5927\u725b  \u6797\u4e8c\u725b  \n\u674e\u4e00\u86cb  \u674e\u4e8c\u86cb  \n\u738b\u4e00\u70ae  \u738b\u4e09\u70ae  \n\u200b```<\/code><\/pre>\n<h2>\u4e94 \u5728\u51fd\u6570\u53c2\u6570\u4e2d\u4f20\u9012<\/h2>\n<p>\u5728\u5176\u4ed6\u5176\u5b83\u7f16\u7a0b\u8bed\u8a00\u53ef\u80fd\u4f1a\u9690\u5f0f\u5730\u5c06\u6570\u7ec4\u4f5c\u4e3a\u5f15\u7528\u6216\u6307\u9488\u5bf9\u8c61\u4f20\u5165\u88ab\u8c03\u7528\u7684\u51fd\u6570\uff0c\u4f46\u5728go\u8bed\u8a00\u4e2d\u6570\u7ec4\u5c31\u662f\u503c\u4f20\u9012\uff0c\u8be6\u7ec6\u5730\u8bf4\uff1a\u5173\u4e8e\u6570\u7ec4\u7684\u8d4b\u503c\u548c\u4f20\u53c2\u4f1a\u590d\u5236\u6574\u4e2a\u6570\u7ec4\uff0c\u64cd\u4f5c\u7684\u90fd\u662f\u526f\u672c\u7684\u503c\uff0c\u4e0d\u4f1a\u6539\u53d8\u672c\u8eab\u7684\u503c\u3002<\/p>\n<p>\u4e3e\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc modifyArray(x [3]int) {\n    fmt.Printf(&quot;\u62f7\u8d1d\u5f97\u5230\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5730\u5740\u662f\uff1a%p\\n&quot;,&amp;x)\n    x[0] = 100\n}\n\nfunc main() {\n    c := [3]int{10, 20, 30}\n    fmt.Printf(&quot;\u539f\u6570\u7ec4\uff0c\u5730\u5740\u662f\uff1a%p\\n&quot;,&amp;c)  \/\/ \u539f\u6570\u7ec4\uff0c\u5730\u5740\u662f\uff1a0xc000018140\n    modifyArray(c) \/\/ \u5728modify\u4e2d\u4fee\u6539\u7684\u662fc\u7684\u526f\u672cx\uff0c\u6253\u5370\u7684\u65b0\u6570\u7ec4\u5730\u5740\uff1a0xc000018180\n    fmt.Println(c) \/\/ \u4ecd\u7136\u4e3a[10 20 30]\n}<\/code><\/pre>\n<p>\u5c0f\u7ec3\u4e60<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc modifyArray2(x [3][2]int) {\n    fmt.Printf(&quot;\u62f7\u8d1d\u5f97\u5230\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5730\u5740\u662f\uff1a%p\\n&quot;, &amp;x)\n    x[2][0] = 100\n}\nfunc main() {\n    \/\/ \u7ec3\u4e601\n    var a = 10                                   \/\/\u5b9a\u4e49\u53d8\u91cfa\n    b := a                                       \/\/\u5c06a\u7684\u503c\u8d4b\u503c\u7ed9b\n    b = 101                                      \/\/\u4fee\u6539b\u7684\u503c\uff0c\u662f\u5426\u4f1a\u5f71\u54cda\uff1f\n    fmt.Printf(&quot;a\u7684\u5185\u5b58\u5730\u5740\u662f%p\\n\uff0cb\u7684\u5185\u5b58\u5730\u5740\u662f%p\\n&quot;, a, &amp;b) \/\/a\u4e0eb\u7684\u5185\u5b58\u5730\u5740\u662f\u5426\u4e00\u6837\uff1f\n\n    \/\/ \u7ec3\u4e602\n    d := [3][2]int{\n        {1, 1},\n        {1, 1},\n        {1, 1},\n    }\n    fmt.Printf(&quot;\u539f\u6570\u7ec4\uff0c\u5730\u5740\u662f\uff1a%p\\n&quot;, &amp;d)\n    modifyArray2(d) \/\/ \u6b64\u5904\u6253\u5370\u7684\u5730\u5740\u4e0e\u4e0a\u4e00\u884c\u4ee3\u7801\u6253\u5370\u7684\u662f\u5426\u4e00\u81f4\uff1f\n    fmt.Println(d)  \/\/\u503c\u4e3a\uff1f\n}<\/code><\/pre>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u4e00\u4e0b\u6570\u7ec4\u56e0\u4e3a\u662f\u503c\u7c7b\u578b\u5e26\u6765\u7684\u5f0a\u7aef<\/p>\n<p>1\u3001\u5728\u51fd\u6570\u53c2\u6570\u4e2d\u662f\u503c\u4f20\u9012\uff0c\u5bfc\u81f4\u4f20\u9012\u5927\u6570\u7ec4\u5c06\u662f\u4f4e\u6548\u7684<\/p>\n<p>2\u3001\u4f20\u9012\u7ed9\u51fd\u6570\u540e\uff0c\u4efb\u4f55\u7684\u4fee\u6539\u90fd\u662f\u53d1\u751f\u5728\u590d\u5236\u7684\u6570\u7ec4\u4e0a\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u4fee\u6539\u8c03\u7528\u65f6\u539f\u59cb\u7684\u6570\u7ec4\u53d8\u91cf\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u6211\u4eec\u53ef\u4ee5\u663e\u5f0f\u5730\u4f20\u5165\u4e00\u4e2a\u6570\u7ec4\u6307\u9488\u6765\u8fbe\u5230\u5f15\u7528\u4f20\u9012\u4e0e\u4fee\u6539\u539f\u503c\u7684\u76ee\u7684\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-go\">func zero(ptr *[32]byte) {\n    *ptr = [32]byte{}  \/\/ \u7ed9[32]byte\u7c7b\u578b\u7684\u6570\u7ec4\u6e05\u96f6\n}\n\n\u6ce8\u610f\uff1a\n[n]*T\uff1a\u8868\u793a\u6570\u7ec4\u7684\u5143\u7d20\u7531\u6307\u9488\u7c7b\u578b\u7ec4\u6210\n*[n]T\uff1a\u8868\u793a\u6570\u7ec4\u6307\u9488<\/code><\/pre>\n<p>\u867d\u7136\u901a\u8fc7\u6307\u9488\u6765\u4f20\u9012\u6570\u7ec4\u53c2\u6570\u662f\u9ad8\u6548\u7684\uff0c\u800c\u4e14\u4e5f\u5141\u8bb8\u5728\u51fd\u6570\u5185\u90e8\u4fee\u6539\u6570\u7ec4\u7684\u503c\uff0c\u4f46\u662f\u6570\u7ec4\u4f9d\u7136\u662f\u50f5\u5316\u7684\u7c7b\u578b\uff0c\u56e0\u4e3a\u6570\u7ec4\u7684\u7c7b\u578b\u5305\u542b\u4e86\u50f5\u5316\u7684\u957f\u5ea6\u4fe1\u606f\uff0c\u4f8b\u5982\uff1a\u4e0a\u9762\u7684zero\u51fd\u6570\u5e76\u4e0d\u80fd\u63a5\u6536\u6307\u5411[16]byte\u7c7b\u578b\u6570\u7ec4\u7684\u6307\u9488\uff0c\u800c\u4e14\u4e5f\u6ca1\u6709\u4efb\u4f55\u6dfb\u52a0\u6216\u5220\u9664\u6570\u7ec4\u5143\u7d20\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u7531\u4e8e\u8fd9\u4e9b\u539f\u56e0\uff0c\u6570\u7ec4\u5f88\u5c11\u7528\u4f5c\u51fd\u6570\u53c2\u6570\uff0c\u6211\u4eec\u4e00\u822c\u4f7f\u7528slice\u6765\u66ff\u4ee3\u6570\u7ec4\u3002\u63a5\u4e0b\u6765\u5c31\u8ba9\u6211\u4eec\u6765\u4ecb\u7ecd\u4e00\u4e0b\u5207\u7247Slice\u5427<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u590d\u5408\u6570\u636e\u7c7b\u578b\u4e4b\u6570\u7ec4Array \u4e00 \u6570\u7ec4\u4ecb\u7ecd \u6570\u7ec4\u662f\u4e00\u7ec4\u540c\u4e00\u7c7b\u6570\u636e\u7684\u96c6\u5408\uff0c\u6570\u7ec4\u5305\u542b\u7684\u5143\u7d20\u4e2a\u6570\u88ab\u79f0\u4e3a\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u53ef [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,449],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/7925"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7925"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/7925\/revisions"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}