{"id":207226,"date":"2025-07-08T09:53:07","date_gmt":"2025-07-08T01:53:07","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207226\/"},"modified":"2025-07-08T09:53:07","modified_gmt":"2025-07-08T01:53:07","slug":"%e7%bb%99%e5%ae%9a%e7%b1%bb%e5%9e%8b-int-%e7%9a%84%e9%9d%9e%e7%b1%bb%e5%9e%8b%e5%8c%96%e5%b8%b8%e9%87%8f%e7%b4%a2%e5%bc%95%e6%98%af%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207226\/","title":{"rendered":"\u201c\u7ed9\u5b9a\u7c7b\u578b int \u7684\u975e\u7c7b\u578b\u5316\u5e38\u91cf\u7d22\u5f15\u201d\u662f\u4ec0\u4e48\u610f\u601d\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u201c\u7ed9\u5b9a\u7c7b\u578b int \u7684\u975e\u7c7b\u578b\u5316\u5e38\u91cf\u7d22\u5f15\u201d\u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-20 22:33:40<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u201c\u7ed9\u5b9a\u7c7b\u578b int \u7684\u975e\u7c7b\u578b\u5316\u5e38\u91cf\u7d22\u5f15\u201d\u662f\u4ec0\u4e48\u610f\u601d\uff1f\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>Go\u89c4\u8303\u7ed9\u51fa\u4e86\u7d22\u5f15\u8868\u8fbe\u5f0f<code>a[x]<\/code>\u7684\u89c4\u5219\uff1a<\/p>\n<p> \u5982\u679c a \u4e0d\u662f\u5730\u56fe\uff1a \u7d22\u5f15 x \u5fc5\u987b\u662f\u6574\u6570\u7c7b\u578b\u6216\u65e0\u7c7b\u578b\u5e38\u91cf \u5e38\u91cf\u7d22\u5f15\u5fc5\u987b\u662f\u975e\u8d1f\u7684\u5e76\u4e14\u53ef\u4ee5\u7528 int \u7c7b\u578b\u7684\u503c\u8868\u793a \u65e0\u7c7b\u578b\u5e38\u91cf\u7d22\u5f15\u7684\u6307\u5b9a\u7c7b\u578b\u4e3a int \u5982\u679c 0 &lt;= x &lt; len(a)\uff0c\u5219\u7d22\u5f15 x \u5728\u8303\u56f4\u5185\uff0c\u5426\u5219\u8d85\u51fa\u8303\u56f4 <\/p>\n<p>\u7b2c\u4e09\u6761\u89c4\u5219\uff08\u65e0\u7c7b\u578b\u5e38\u91cf\u7d22\u5f15\u7684\u7ed9\u5b9a\u7c7b\u578b\u4e3a int \uff09\u5230\u5e95\u662f\u4ec0\u4e48\u610f\u601d\uff1f\u6709\u6548\u7684\u8868\u8fbe\u5f0f <code>a[1.0]<\/code> \u662f\u5426\u4e0e\u8be5\u89c4\u5219\u76f8\u77db\u76fe\uff1f<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u8fd0\u884c\u65f6\u4f7f\u7528\u7684\u6bcf\u4e2a\u503c\u90fd\u5fc5\u987b\u6709\u4e00\u4e2a\u7c7b\u578b\u3002\u5982\u679c\u60a8\u4f7f\u7528\u975e\u7c7b\u578b\u5316\u5e38\u91cf\uff0c\u5b83\u5c06\u88ab\u8f6c\u6362\u4e3a\u7c7b\u578b\u5316\u503c\uff0c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a<\/p>\n<pre>fmt.printf(\"%t %v\", 1, 1)<\/pre>\n<p><code>1<\/code> \u662f\u4e00\u4e2a\u65e0\u7c7b\u578b\u5e38\u91cf\uff0c\u4f46\u5f53\u4f20\u9012\u7ed9 <code>fmt.printf()<\/code> \u65f6\uff0c\u5fc5\u987b\u5c06\u5176\u8f6c\u6362\u4e3a\u7c7b\u578b\u5316\u503c\u3002\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u5c06\u4f7f\u7528\u5176\u9ed8\u8ba4\u7c7b\u578b\uff0c\u5373 <code>int<\/code>\uff0c\u56e0\u6b64\u4e0a\u9762\u7684\u793a\u4f8b\u6253\u5370 <code>int 1<\/code>\u3002<\/p>\n<ul>\n<li>\u975e\u7c7b\u578b\u5316\u5e38\u91cf\u7d22\u5f15\u7684\u7ed9\u5b9a\u7c7b\u578b\u4e3a <code>int<\/code><\/li>\n<\/ul>\n<p>\u8fd9\u610f\u5473\u7740\uff0c\u5982\u679c\u60a8\u5bf9\u975e\u7c7b\u578b\u5316\u7d22\u5f15\uff08\u5b83\u6ca1\u6709\u7c7b\u578b\uff09\u4f7f\u7528\u5e38\u91cf\u503c\uff0c\u5219\u5f53\u8be5\u5e38\u91cf\u8f6c\u6362\u4e3a\u7c7b\u578b\u5316\u503c\u65f6\uff0c\u5c06\u4f7f\u7528 <code>int<\/code>\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>s := []int{1, 2, 3}\nfmt.println(s[1])<\/pre>\n<p>\u8fd9\u91cc\u4f7f\u7528\u65e0\u7c7b\u578b\u5e38\u91cf <code>1<\/code> \u4f5c\u4e3a\u7d22\u5f15\uff0c\u56e0\u6b64\u5b83\u5c06\u88ab\u8f6c\u6362\/\u7528\u4f5c <code>int<\/code>\u3002<\/p>\n<p>\u53cd\u4f8b\uff1a<\/p>\n<pre>fmt.println(s[int32(1)])<\/pre>\n<p>\u6b64\u5904 <code>s<\/code> \u4f7f\u7528\u952e\u5165\u503c <code>int32(1)<\/code> \u8fdb\u884c\u7d22\u5f15\u3002\u8fd9\u662f\u6709\u6548\u7684\uff0c\u56e0\u4e3a <code>int32<\/code> \u662f\u6574\u6570\u7c7b\u578b\u3002<\/p>\n<p>\u8be5\u89c4\u5219\u53ea\u662f\u8bf4\uff0c\u5982\u679c\u60a8\u4f7f\u7528\u65e0\u7c7b\u578b\u5e38\u91cf\uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u8d4b\u4e88 <code>int<\/code> \u7c7b\u578b\uff0c\u800c\u4e0d\u662f <code>int32<\/code> \u7c7b\u578b\u3002<\/p>\n<p>\u8fd9\u5728\u4f7f\u7528 \u65f6\u53ef\u80fd\u770b\u8d77\u6765\u5f88\u660e\u663e\uff0c\u4f46\u5728\u4f7f\u7528\u5176\u4ed6\u7c7b\u578b\u7684\u6587\u5b57\uff08\u4f8b\u5982 \uff09\u65f6\u5219\u4e0d\u7136\u3002<\/p>\n<p>\u4ee5\u4e0b\u5185\u5bb9\u4e5f\u6709\u6548\uff1a<\/p>\n<pre>fmt.Println(s['\\x00'])<\/pre>\n<p>\u4e0a\u9762\u7684\u793a\u4f8b\u4f7f\u7528\u7b26\u6587\u6587\u5b57 <code>'\\x00'<\/code> \u4f5c\u4e3a\u7d22\u5f15\uff0c\u5b83\u4e5f\u662f\u4e00\u4e2a\u65e0\u7c7b\u578b\u5e38\u91cf\uff0c\u4f46\u5b83\u5177\u6709\u4e0d\u540c\u7684\u9ed8\u8ba4\u7c7b\u578b\u3002\u7b26\u6587\u6587\u5b57\u7684\u9ed8\u8ba4\u7c7b\u578b\u4e3a <code>rune<\/code>\uff0c\u5b83\u662f <code>int32<\/code> \u7684\u522b\u540d\u3002\u5f15\u7528\u7684\u7d22\u5f15\u89c4\u5219\u6307\u51fa\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u7d22\u5f15\u7684\u7c7b\u578b\u5c06\u4e3a <code>int<\/code>\uff0c\u800c\u4e0d\u662f <code>int32<\/code>\u3002<\/p>\n<p>\u4e8b\u5b9e\u5e76\u975e\u5982\u6b64\u3002 <code>1.0<\/code> \u548c <code>1<\/code> \u662f\u76f8\u540c\u7684\u6570\u5b57\uff08\u6570\u5b66\u4e0a\uff09\uff0c\u56e0\u6b64\u65e0\u7c7b\u578b\u5e38\u91cf <code>1.0<\/code> \u53ef\u4ee5\u88ab\u8d4b\u4e88\u7c7b\u578b <code>int<\/code>\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u5982\u679c\u60a8\u5c1d\u8bd5\u6307\u5b9a <code>a[1.5]<\/code>\uff0c\u5219\u4f1a\u6536\u5230\u9519\u8bef\u6d88\u606f\uff0c\u56e0\u4e3a <code>1.5<\/code> \u4e0d\u662f\u6574\u6570\u3002<\/p>\n<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u201c\u7ed9\u5b9a\u7c7b\u578b int \u7684\u975e\u7c7b\u578b\u5316\u5e38\u91cf\u7d22\u5f15\u201d\u662f\u4ec0\u4e48\u610f\u601d\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207226","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207226"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207226\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}