{"id":397,"date":"2023-09-11T00:08:34","date_gmt":"2023-09-10T16:08:34","guid":{"rendered":"https:\/\/9iwd.top\/?p=397"},"modified":"2023-09-11T00:08:36","modified_gmt":"2023-09-10T16:08:36","slug":"10-2-%e5%86%85%e5%ad%98%e5%9b%9b%e5%8c%ba-%e5%85%a8%e5%b1%80%e5%8c%ba","status":"publish","type":"post","link":"http:\/\/9iwd.top\/?p=397","title":{"rendered":"10.2 \u5185\u5b58\u56db\u533a-\u5168\u5c40\u533a"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\t \/\/ \u8f93\u51fa\u6d41\u5e93\r\nusing namespace std; \/\/ \u4f7f\u7528\u6807\u51c6\u547d\u540d\u7a7a\u95f4\r\n\/\/ \u5168\u5c40\u53d8\u91cf\r\nint all_a = 10;\r\nint all_b = 10;\r\n\r\n\/\/ const\u4fee\u9970\u5168\u5c40\u53d8\u91cf\uff0c\u5168\u5c40\u5e38\u91cf\r\nconst int con_all_a = 10;\r\nconst int con_all_b = 10;\r\n\r\n\/\/ \u8bfe\u7a0b\uff1a\u6838\u5fc3\u7f16\u7a0bday1 - \u8ba4\u6e05\u5185\u5b58\u56db\u533a\u4e4b\u4ee3\u7801\u533a\u3001\u5168\u5c40\u533a\r\n\/* \u4ee3\u7801\u533a\uff1a\u5b58\u653e\u51fd\u6570\u4f53\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u6709\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u7ba1\u7406\r\n   \u5168\u5c40\u533a\uff1a\u5b58\u653e\u5168\u5c40\u53d8\u91cf\u3001\u9759\u6001\u53d8\u91cf\u3001\u5e38\u91cf\r\n   \u6808  \u533a\uff1a\u7531\u7f16\u8bd1\u5668\u81ea\u52a8\u5206\u914d\u91ca\u653e\uff0c\u5b58\u653e\u51fd\u6570\u548c\u53c2\u6570\u503c\uff0c\u5c40\u90e8\u53d8\u91cf\u7b49\r\n   \u5806  \u533a\uff1a\u6709\u7a0b\u5e8f\u5458\u5206\u914d\u548c\u91ca\u653e\uff0c\u82e5\u7a0b\u5e8f\u5458\u4e0d\u91ca\u653e\uff0c\u7a0b\u5e8f\u7ed3\u675f\u65f6\u7531\u7cfb\u7edf\u56de\u6536*\/\r\n\r\n\/\/ \u7a0b\u5e8f\u5165\u53e3\u51fd\u6570\r\nint main()\r\n{\r\n\tsystem(\"chcp 65001\"); \/\/ \u4e34\u65f6\u8bbe\u7f6eUTF-8\u7f16\u7801\r\n\t\/\/ \u521b\u5efa\u5c40\u90e8\u53d8\u91cf\r\n\tint a = 10;\r\n\tint b = 10;\r\n\t\/\/(int) = \u5f3a\u5236\u8f6c\u4e3a\u6574\u6570\u578b &amp;\u53d6\u53d8\u91cf\u5730\u5740(16\u8fdb\u5236)\r\n\tcout &lt;&lt; \"------ \u5c40\u90e8\u53d8\u91cf ------\" &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u53d8\u91cf\u5730\u5740a\u4e3a\uff1a\" &lt;&lt; (long long)&amp;a &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u53d8\u91cf\u5730\u5740b\u4e3a\uff1a\" &lt;&lt; (long long)&amp;b &lt;&lt; endl;\r\n\tcout &lt;&lt; \"------ \u5168\u5c40\u53d8\u91cf ------\" &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u53d8\u91cf\u5730\u5740all_a\u4e3a\uff1a\" &lt;&lt; (long long)&amp;all_a &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u53d8\u91cf\u5730\u5740all_b\u4e3a\uff1a\" &lt;&lt; (long long)&amp;all_b &lt;&lt; endl;\r\n\t\/\/ \u521b\u5efa\u9759\u6001\u53d8\u91cf\r\n\tstatic int t_a = 10;\r\n\tstatic int t_b = 10;\r\n\tcout &lt;&lt; \"------ \u9759\u6001\u53d8\u91cf ------\" &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u53d8\u91cf\u5730\u5740t_a\u4e3a\uff1a\" &lt;&lt; (long long)&amp;t_a &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u53d8\u91cf\u5730\u5740t_b\u4e3a\uff1a\" &lt;&lt; (long long)&amp;t_b &lt;&lt; endl;\r\n\t\/\/ \u5e38\u91cf \u5b57\u7b26\u4e32\u5e38\u91cf\uff0c\u6240\u6709\u53cc\u5f15\u53f7\u5305\u542b\u7684\u5747\u4e3a\u5e38\u91cf\r\n\tcout &lt;&lt; \"------ \u5e38    \u91cf ------\" &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u5e38\u91cf\u5730\u5740\u4e3a\uff1a\" &lt;&lt; (long long)&amp;\"\u8fd9\u662f\u5e38\u91cf\" &lt;&lt; endl;\r\n\t\/\/ const\u4fee\u9970\u7684\u5c40\u90e8\u53d8\u91cf\r\n\tconst int con_a = 10;\r\n\tconst int con_b = 10;\r\n\tcout &lt;&lt; \"------ \u5c40\u90e8\u5e38\u91cf ------\" &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u5e38\u91cf\u5730\u5740con_a\u4e3a\uff1a\" &lt;&lt; (long long)&amp;con_a &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u5e38\u91cf\u5730\u5740con_b\u4e3a\uff1a\" &lt;&lt; (long long)&amp;con_b &lt;&lt; endl;\r\n\tcout &lt;&lt; \"------ \u5168\u5c40\u5e38\u91cf ------\" &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u5e38\u91cf\u5730\u5740con_all_a\u4e3a\uff1a\" &lt;&lt; (long long)&amp;con_all_a &lt;&lt; endl;\r\n\tcout &lt;&lt; \"\u5e38\u91cf\u5730\u5740con_all_b\u4e3a\uff1a\" &lt;&lt; (long long)&amp;con_all_b &lt;&lt; endl;\r\n\r\n\tsystem(\"pause\"); \/\/ \u63a7\u5236\u53f0\u6682\u505c\uff0c\u7b49\u5f85\u4e0b\u4e00\u6b65\u64cd\u4f5c\r\n\treturn 0;\t\t \/\/ \u7ed3\u675f\u8fd4\u56de\u503c\uff1a0\r\n}\r\n\/*\r\n\u8fd9\u91cc\u662f\u56e0\u4e3a\u57fa\u4e8eLinux\u5185\u6838\u53ea\u768464\u4f4d\u7cfb\u7edf\u4e0a\u6307\u9488\u7c7b\u578b\u5360\u75288\u4e2a\u5b57\u8282\uff0c\r\n\u800cint\u7c7b\u578b\u5360\u75284\u4e2a\u5b57\u8282\uff0c\u6240\u4ee5\u4f1a\u51fa\u73b0loses precision.\r\n\u53ef\u4ee5\u5148\u5c06int \u8f6c\u6210long\u7c7b\u578b\uff0clong\u7c7b\u578b\u53ef\u4ee5\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u5230int\u7c7b\u578b\u3002\u76f4\u63a5\u4fee\u6539\u4e3along long\u5373\u53ef\r\n\r\n\u547d\u540d\r\nc -> const\t\u5e38\u91cf\u5173\u952e\u5b57\r\ng -> global\t\u5168\u5c40\u3001\u5168\u90e8\u7684\u610f\u601d\r\nl -> local\t\u5f53\u524d\u3001\u5c40\u90e8\u7684\u610f\u601d\r\n\r\n\u4e0d\u5728\u5168\u5c40\u533a\u4e2d\r\n \u5c40\u90e8\u53d8\u91cf\r\n const\u4fee\u9970\u7684\u5c40\u90e8\u53d8\u91cf(\u5c40\u90e8\u5e38\u91cf)\r\n\r\n\u5728\u5168\u5c40\u533a\u4e2d\r\n \u5168\u5c40\u53d8\u91cf\r\n \u9759\u6001\u53d8\u91cf static\u5173\u952e\u5b57\u4fee\u9970\u7684\u53d8\u91cf\r\n \u5e38\u91cf\r\n  \u5b57\u7b26\u4e32\u5e38\u91cf\r\n  const\u4fee\u9970\u7684\u5168\u5c40\u53d8\u91cf\uff08\u5168\u5c40\u5e38\u91cf\uff09\r\n*\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"_links":{"self":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/posts\/397"}],"collection":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=397"}],"version-history":[{"count":1,"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions"}],"predecessor-version":[{"id":398,"href":"http:\/\/9iwd.top\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions\/398"}],"wp:attachment":[{"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/9iwd.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}