{"id":464,"date":"2015-08-12T20:20:35","date_gmt":"2015-08-12T12:20:35","guid":{"rendered":"http:\/\/yangwang.hk\/?p=464"},"modified":"2015-08-12T20:20:35","modified_gmt":"2015-08-12T12:20:35","slug":"3-4%e3%80%81%e8%bf%90%e7%ae%97%e7%ac%a6%e4%b8%8e%e4%bc%98%e5%85%88%e7%ba%a7%e4%b8%8a","status":"publish","type":"post","link":"https:\/\/yangwang.hk\/?p=464","title":{"rendered":"3.4\u3001\u8fd0\u7b97\u7b26\u4e0e\u4f18\u5148\u7ea7(\u4e0a)"},"content":{"rendered":"<p>\u6211\u4eec\u5728\u53d8\u91cf\u7684\u8ba1\u7b97\u4e00\u8282\u4e2d\u5df2\u7ecf\u63d0\u5230\u4e86\u8fd0\u7b97\u7b26\u7684\u6982\u5ff5\uff08\u867d\u7136\u4f60\u53ef\u80fd\u5230\u73b0\u5728\u53ea\u7528\u8fc7\u52a0\u51cf\u4e58\u9664\uff09<\/p>\n<p>\u800c\u73b0\u5728\u6211\u4eec\u5c06\u5b66\u4e60c\u8bed\u8a00\u5927\u90e8\u5206\u7684\u8fd0\u7b97\u7b26\uff0c\u5e76\u4e14\u641e\u6e05\u695a\u5b83\u4eec\u4e4b\u95f4\u7684\u4f18\u5148\u7ea7<\/p>\n<p>\u9996\u5148\u6765\u770b\u770b\u4ec0\u4e48\u662f\u8fd0\u7b97\u7b26<\/p>\n<h2>\u8fd0\u7b97\u7b26\uff08operator\uff09<\/h2>\n<p>\u8fd0\u7b97\u7b26\u5c31\u662f\u7528\u6765\u8868\u793a\u8fd0\u7b97\u5173\u7cfb\u7684\u7b26\u53f7\uff0c\u4f8b\u5982\u201c+\u201d\u5c31\u662f\u628a\u201c+\u201d\u4e24\u8fb9\u7684\u6570\u5b57\u76f8\u52a0<\/p>\n<p>\u6ce8\u610f\uff0c\u5728\u7b26\u53f7\u524d\u9762\u5e76\u6ca1\u6709\u6570\u5b57\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e00\u4e2a\u8fd0\u7b97\u7b26\u53ef\u80fd\u5e76\u4e0d\u662f\u53ea\u7531\u4e00\u4e2a\u7b26\u53f7\u7ec4\u6210<\/p>\n<h3>\u8d4b\u503c\u8fd0\u7b97\u7b26\u2014\u2014\u201c=\u201d<\/h3>\n<p>\u8d4b\u503c\u8fd0\u7b97\u7b26=\uff08assignment opeartor\uff09<\/p>\n<p>\u8fd9\u4e2a\u7b26\u53f7\u7684\u6570\u5b66\u610f\u4e49\u5f80\u5f80\u4f1a\u7ed9\u521d\u5b66\u8005\u5e26\u6765\u5e72\u6270<\/p>\n<p>\u5728\u6570\u5b66\u4e2d\u7b26\u53f7\u201c=\u201d\u7528\u6765\u8868\u793a\u201c\u76f8\u7b49\u201d\uff0c\u4f8b\u5982x=1\u5c31\u610f\u5473\u7740x\u7684\u503c\u548c1\u76f8\u7b49<\/p>\n<p>\u5728\u67d0\u4e9b\u7f16\u7a0b\u8bed\u8a00\u4e2d\uff0c\u201c=\u201d\u4e5f\u5177\u6709\u4e0a\u8ff0\u7684\u610f\u4e49\uff0c\u53ef\u60dc\u7684\u662fC\u8bed\u8a00\u5e76\u4e0d\u5728\u5176\u4e2d<\/p>\n<p>C\u8bed\u8a00\u4e2d\u7b26\u53f7\u201c=\u201d\u8868\u793a\u8d4b\u503c\uff0c\u8ba9\u6211\u4eec\u501f\u75282.3\u4e2d\u7684\u4e00\u5e45\u56fe\u6765\u8bf4\u660e\u8fd9\u6837\u4e00\u4e2a\u8fc7\u7a0b<\/p>\n<p><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2014\/12\/2014-12-27-19-39-09.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-261\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2014\/12\/2014-12-27-19-39-09.png\" alt=\"2014-12-27 19 39 09\" width=\"600\" height=\"240\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2014\/12\/2014-12-27-19-39-09.png 600w, https:\/\/yangwang.hk\/wp-content\/uploads\/2014\/12\/2014-12-27-19-39-09-300x120.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2aint\u7c7b\u578b\u7684\u53d8\u91cfa\uff08\u540e\u6587\u4e2d\u672a\u6ce8\u660e\u7684a\u5747\u4ee3\u8868\u6b64\u53d8\u91cf\uff09\u3002\u90a3\u4e48a=12\u7684\u610f\u4e49\u5219\u662f\u5c0612\u8fd9\u4e2a\u6570\u5b57\u5b58\u653e\u5230a\u6240\u4ee3\u8868\u7684\u50a8\u5b58\u7a7a\u95f4<\/p>\n<p>\u6267\u884c\u540e\uff0c\u65e0\u8bbaa\u539f\u6765\u7684\u503c\u662f\u591a\u5c11\uff0c\u5230\u8fd9\u91cc\u90fd\u4f1a\u53d8\u621012\uff08\u5426\u5219\u8bf4\u660e\u4f60\u7684\u7535\u8111\u574f\u4e86\uff09<\/p>\n<p>\u6267\u884c\u65f6\uff0c\u987a\u5e8f\u663e\u7136\u662f\u4ece\u53f3\u5f80\u5de6\u7684\u3002<\/p>\n<p>\u5982\u679c\u4f60\u73b0\u5728\u8fd8\u8ba4\u4e3a\u8fd9\u91cc\u7684\u201c=\u201d\u548c\u6570\u5b66\u4e2d\u5e76\u6ca1\u6709\u591a\u5927\u7684\u533a\u522b\uff0c\u90a3\u4e48\u8bf7\u601d\u8003\u4e0b\u9762\u7684\u8fd9\u4e2a\u8bed\u53e5<\/p>\n<p>a = a + 1;<span id=\"transmark\"><\/span><\/p>\n<p>\u5728\u6570\u5b66\u4e2d\uff0c\u8fd9\u6837\u7684\u7b49\u5f0f\u663e\u7136\u662f\u6ca1\u6709\u610f\u4e49\u7684\uff0c\u56e0\u4e3a\u4f60\u4e0d\u53ef\u80fd\u627e\u5230\u4e00\u4e2a\u6570\u5b57a\uff0c\u4f7f\u5f97\u4ed6\u52a0\u4e0a1\u4ecd\u7136\u7b49\u4e8e\u4ed6\u81ea\u5df1<\/p>\n<p>\u7136\u800c\u5728\u7f16\u7a0b\u4e2d\uff0c\u8fd9\u6837\u7684\u8bed\u53e5\u5374\u5f88\u5e38\u7528\uff0c\u7531\u4e8e\u6267\u884c\u987a\u5e8f\u662f\u4ece\u53f3\u5f80\u5de6\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4<\/p>\n<p>\u8ba1\u7b97\u673a\u4f1a\u5148\u8ba1\u7b97a+1\u7684\u503c\uff0c\u7136\u540e\u518d\u5c06\u65b0\u7684\u503c\u8d4b\u503c\u7ed9a<\/p>\n<p>\u8fd9\u6837\u5c31\u6d89\u53ca\u5230\u4e86\u64cd\u4f5c\u7684\u987a\u5e8f\u4e0e\u64cd\u4f5c\u7684\u5bf9\u8c61<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u8d4b\u503c\u64cd\u4f5c\u6c38\u8fdc\u4ece\u53f3\u5f80\u5de6\u8fdb\u884c\uff01<\/strong><\/span><\/p>\n<p>\u5728\u8d4b\u503c\u53f7\u7684\u5de6\u53f3\u4e24\u8fb9\u5404\u6709\u4e00\u4e2a\u64cd\u4f5c\u7684\u5bf9\u8c61\uff0c\u7528\u4e13\u4e1a\u4e00\u70b9\u7684\u8bdd\u6765\u8bf4\uff0c\u53eb\u505a\u64cd\u4f5c\u6570\uff08operand\uff09<\/p>\n<p>\u50cf\u8fd9\u6837\u6709\u4e24\u4e2a\u64cd\u4f5c\u6570\u7684\u8fd0\u7b97\u7b26\u53eb\u505a<strong>\u53cc\u76ee\u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>\u800c\u5728\u8d4b\u503c\u53f7\u7684\u5de6\u8fb9\u7684\u64cd\u4f5c\u6570\uff0c\u53eb\u505a<strong>\u5de6\u503c<\/strong>\uff08\u5de6\u8fb9\u5f53\u7136\u53eb\u5de6\u503c\uff0c\u4ed6\u7684\u82f1\u6587\u662flvalue\uff0c\u4e5f\u5c31\u662fleft value\uff09<\/p>\n<p>\u5728\u8d4b\u503c\u53f7\u7684\u53f3\u8fb9\u5219\u662f<strong>\u53f3\u503c<\/strong>\uff08rvalue\uff09<\/p>\n<p>\u663e\u7136\uff0c\u4e00\u4e2a\u5408\u6cd5\u7684\u5de6\u503c\u5e94\u8be5\u662f\u80fd\u591f\u4fee\u6539\u7684\uff08\u5426\u5219\u600e\u4e48\u8fdb\u884c\u8d4b\u503c\u64cd\u4f5c\uff1f\uff09\uff0c\u5728\u8ba1\u7b97\u673a\u4e0a\u5c31\u5e94\u8be5\u662f\u4e00\u5757\u80fd\u591f\u4fee\u6539\uff08\u5199\u5165\uff09\u7684\u50a8\u5b58\u533a\u57df<\/p>\n<p>\u50cf1=a\u8fd9\u6837\u7684\u64cd\u4f5c\u662f\u4e0d\u5408\u6cd5\u7684\uff0c\u56e0\u4e3a1\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u5b83\u5e76\u4e0d\u662f\u8ba1\u7b97\u673a\u4e0a\u7684\u4e00\u5757\u80fd\u4fee\u6539\u7684\u50a8\u5b58\u533a\u57df<\/p>\n<p>\u7528\u901a\u4fd7\u4e00\u70b9\u7684\u8bdd\u6765\u8bf4\uff0c\u8d4b\u503c\u7b26\u53f7\u7684\u5de6\u8fb9\u5fc5\u987b\u662f\u4e00\u4e2a\u53d8\u91cf<\/p>\n<p>\u4e0d\u8fc7\u592a\u4fd7\u767d\u7684\u8bed\u8a00\u4e5f\u4e0d\u597d\uff0c\u8fd9\u6837\u62ff\u51fa\u53bb\u600e\u4e48\u88c5\u903c\u561b\u3002\u5f53\u7136\u6211\u4eec\u6709\u903c\u683c\u66f4\u9ad8\u7684\u8bf4\u6cd5\uff0c\u90a3\u5c31\u662f\uff1a<\/p>\n<p><strong>\u8d4b\u503c\u7b26\u53f7\u7684\u5de6\u64cd\u4f5c\u6570\u5fc5\u987b\u662f\u4e00\u4e2a\u53ef\u4fee\u6539\u7684\u5de6\u503c<\/strong>\uff08modifiable lvalue\uff09\uff08\u5514\uff0c\u597d\u50cf\u903c\u683c\u4e5f\u4e0d\u662f\u592a\u9ad8\u2026\u2026\uff09<\/p>\n<p>\u65e2\u7136\u6709\u201c\u53ef\u4fee\u6539\u7684\u5de6\u503c\u201d\u8fd9\u79cd\u8bf4\u6cd5\uff0c\u4e5f\u5c31\u610f\u5473\u7740\u8fd8\u6709\u201c\u4e0d\u53ef\u4fee\u6539\u7684\u5de6\u503c\u201d\uff0c\u4e0a\u9762\u7684\u5e38\u65701\u5c31\u662f\u4e00\u4e2a\u4f8b\u5b50<\/p>\n<p>\u81f3\u4e8e\u53f3\u503c\uff0c\u5b83\u7684\u8981\u6c42\u5c31\u6ca1\u6709\u90a3\u4e48\u591a\u4e86<\/p>\n<p>\u672f\u8bed\u201c\u53f3\u503c\u201d\uff08rvalue\uff09\u6307\u7684\u662f\u8d4b\u7ed9\u53ef\u4fee\u6539\u7684\u5de6\u503c\u7684\u91cf\uff08\u8fd9\u53e5\u8bdd\u6765\u81ea\u4e8e\u300aC Primer Plus\u300b\uff09<\/p>\n<p>\u5bf9\u4e8e\u53f3\u503c\u7684\u8981\u6c42\u662f\uff0c\u53ea\u8981\u5b83\u662f\u4e00\u4e2a\u503c\uff0c\u90a3\u4e48\u4ed6\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u53f3\u503c<\/p>\n<p>\u8fd9\u610f\u5473\u7740\u5e38\u91cf\u3001\u53d8\u91cf\u6216\u8005\u662f\u4e00\u4e2a\u6709\u503c\u5f97\u8868\u8fbe\u5f0f\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u53f3\u503c<\/p>\n<p>C\u8bed\u8a00\u7684\u8d4b\u503c\u64cd\u4f5c\u53ef\u4ee5\u63a5\u53d7\u4e00\u79cd\u975e\u5e38\u5947\u602a\u7684\u5199\u6cd5<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709int\u7c7b\u578b\u7684b\u3001c\u3001d\u3001e\u56db\u4e2a\u53d8\u91cf\uff0c\u8981\u5c06a\u53d8\u91cf\u7684\u503c\u5206\u522b\u8d4b\u503c\u7ed9\u4ed6\u4eec<\/p>\n<p>\u4e00\u79cd\u5199\u6cd5\u662f<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nb=a;\r\nc=a;\r\nd=a;\r\ne=a;\r\n<\/pre>\n<p>\u800c\u53e6\u4e00\u79cd\u5199\u6cd5\u662f<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nb=c=d=e=a;\r\n<\/pre>\n<p>\u7531\u4e8e\u8d4b\u503c\u8fc7\u7a0b\u662f\u4ece\u53f3\u5f80\u5de6\u8fdb\u884c\u7684\uff0c\u8ba1\u7b97\u673a\u9996\u5148\u53d6\u51faa\u7684\u503c\uff0c\u5c06\u4ed6\u8d4b\u503c\u7ed9e\uff0c\u518d\u53d6\u51fae\u7684\u503c\u5c06\u4ed6\u8d4b\u503c\u7ed9d\uff0c\u4f9d\u6b64\u7c7b\u63a8\u5b8c\u6210\u8d4b\u503c\u7684\u64cd\u4f5c<\/p>\n<h3>\u52a0\u6cd5\u4e0e\u51cf\u6cd5\u8fd0\u7b97\u7b26\u2014\u2014\u201c+\u201d\u3001\u201c-\u201d<\/h3>\n<p>\u52a0\u6cd5\u8fd0\u7b97\u7b26+\uff08addition operator\uff09\u7684\u610f\u4e49\u548c\u6570\u5b66\u4e2d\u7c7b\u4f3c\uff0c\u5b83\u5c06\u4e24\u4fa7\u7684\u64cd\u4f5c\u6570\u76f8\u52a0\u8d77\u6765\uff08\u663e\u7136\u52a0\u6cd5\u8fd0\u7b97\u7b26\u662f\u4e00\u4e2a\u53cc\u76ee\u8fd0\u7b97\u7b26\uff09<\/p>\n<p>\u52a0\u6cd5\u8fd0\u7b97\u7b26\u5bf9\u4e8e\u64cd\u4f5c\u6570\u7684\u8981\u6c42\u662f\u53ea\u8981\uff08\u5728\u8fd0\u7b97\u65f6\uff09\u6709\u786e\u5b9a\u503c\u7684\u7684\u5bf9\u8c61\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u64cd\u4f5c\u6570\uff0c\u4e5f\u5c31\u662f\u8bf4\u52a0\u6cd5\u7684\u64cd\u4f5c\u6570\u53ef\u4ee5\u4e3a\u53d8\u91cf\uff0c\u5e38\u91cf\u6216\u8005\u6709\u503c\u7684\u8868\u8fbe\u5f0f<\/p>\n<p>\u7c7b\u4f3c\u7684\uff0c\u51cf\u6cd5\u8fd0\u7b97\u7b26-\uff08subtraction operator\uff09\u4ece\u524d\u9762\u7684\u64cd\u4f5c\u6570\u4e2d\u51cf\u53bb\u540e\u9762\u7684\u64cd\u4f5c\u6570\u7684\u503c\uff0c\u540c\u6837\uff0c\u5e38\u91cf\u53d8\u91cf\u548c\u6709\u503c\u7684\u8868\u8fbe\u5f0f\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u64cd\u4f5c\u6570<\/p>\n<p>\u5f53\u7136\uff0c\u5982\u679c\u8fd0\u7b97\u7b26\u7684\u4e24\u4e2a\u64cd\u4f5c\u6570\u7c7b\u578b\u4e0d\u540c\uff0c\u6709\u53ef\u80fd\u65e0\u6cd5\u8fdb\u884c\u8fd0\u7b97\uff0c\u8fd9\u4e2a\u95ee\u9898\u7b49\u5230\u6211\u4eec\u540e\u9762\u518d\u8bf4<\/p>\n<h3>\u8d1f\u53f7\u8fd0\u7b97\u7b26\u4e0e\u6b63\u53f7\u8fd0\u7b97\u7b26<\/h3>\n<p>\u8d1f\u53f7\u8fd0\u7b97\u7b26-\u548c\u6b63\u53f7\u8fd0\u7b97\u7b26+\u7684\u7b26\u53f7\u548c\u4e0a\u9762\u7684\u52a0\u51cf\u7b26\u53f7\u76f8\u540c\uff0c\u4e0d\u540c\u7684\u7528\u6cd5\u8d4b\u4e88\u4e86\u4ed6\u4eec\u4e0d\u540c\u7684\u542b\u4e49\u3002<\/p>\n<p>\u5728\u6570\u5b66\u4e2d\uff0c\u6211\u4eec\u5728\u4e00\u4e2a\u6570\u5b57\u524d\u9762\u52a0\u4e0a\u201c\u8d1f\u53f7\u201d\u6765\u8868\u793a\u5b83\u7684\u76f8\u53cd\u6570\uff0c\u4f8b\u5982-3\uff0c-\uff08-9\uff09<\/p>\n<p>\u7c7b\u4f3c\u7684\uff0c\u5728\u4e00\u4e2a\u503c\u5f97\u524d\u9762\u52a0\u4e0a\u8d1f\u53f7\u8fd0\u7b97\u7b26\uff0c\u4fbf\u5f97\u5230\u4e86\u5b83\u7684\u76f8\u53cd\u6570\uff0c\u5982<\/p>\n<p>a = -1<\/p>\n<p>a=-a<\/p>\n<p>\u5728\u4e00\u4e2a\u503c\u5f97\u524d\u9762\u52a0\u4e0a\u6b63\u53f7\u8fd0\u7b97\u7b26\u5e76\u4e0d\u6539\u53d8\u5b83\u7684\u7b26\u53f7\uff0c\u4f8b\u5982\u5f53a\u4e3a-1\u65f6\uff0c\u8fdb\u884c\u4e0b\u9762\u7684\u64cd\u4f5c<\/p>\n<p>a=+a;<\/p>\n<p>a\u4ecd\u7136\u4e3a-1\uff0c\u800c\u4e0d\u662f1\uff01<\/p>\n<p>\u6b63\u53f7\u8fd0\u7b97\u7b26\u662f\u5728C90\u6807\u51c6\u4e2d\u52a0\u5165\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u53ea\u80fd\u5728\u652f\u6301C90\u53ca\u4ee5\u540e\u6807\u51c6\u7684\u7f16\u8bd1\u5668\u4e0a\u4f7f\u7528\u4e0a\u8ff0\u7684\u5199\u6cd5\uff0c\u5426\u5219\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u7529\u4f60\u4e00\u8138error\uff01<\/p>\n<p>\u663e\u7136\u7684\uff0c\u8fd9\u4e00\u6b21\u7684\u4e24\u4e2a\u7b26\u53f7\u90fd\u53ea\u9700\u8981\u4e00\u4e2a\u64cd\u4f5c\u6570\uff0c\u8fd9\u6837\u7684\u8fd0\u7b97\u7b26\u53eb\u505a\u201c\u5355\u76ee\u8fd0\u7b97\u7b26\u201d\uff08unary operator\uff0c\u4e5f\u6709\u8bd1\u4e3a\u201c\u4e00\u5143\u8fd0\u7b97\u7b26\u201d\u7684\uff09<\/p>\n<h3>\u00a0\u4e58\u6cd5\u8fd0\u7b97\u7b26\u2014\u2014\u201c*\u201d<\/h3>\n<p>\u8fd9\u4e00\u4e2a\u7b26\u53f7\u4e5f\u548c\u6570\u5b66\u4e2d\u7c7b\u4f3c\uff0c\u4e5f\u662f\u4e00\u4e2a\u53cc\u76ee\u8fd0\u7b97\u7b26\uff0c\u53c2\u8003\u524d\u9762\u6240\u8bb2\u7684\u52a0\u51cf\u8fd0\u7b97\u7b26\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u4f53\u4f1a\u5b83<\/p>\n<h3>\u9664\u6cd5\u8fd0\u7b97\u7b26\u2014\u2014\u201c\/\u201d<\/h3>\n<p>\u6211\u7279\u610f\u5c06\u4ed6\u4e0e\u4e58\u6cd5\u5206\u5f00\u6765\uff0c\u56e0\u4e3a\u4ed6\u548c\u4e58\u6cd5\u76f8\u6bd4\uff0c\u591a\u4e86\u4e00\u4e9b\u65b0\u7684\u7279\u6027<\/p>\n<p>\u9996\u5148\u4f7f\u7528\u65b9\u6cd5\u548c\u542b\u4e49\u7c7b\u4f3c\u4e8e\u6570\u5b66\uff0c\u4fbf\u4e0d\u518d\u7d2f\u8ff0<\/p>\n<p>\u6570\u5b66\u4e2d\u4e00\u4e2a\u6570\u9664\u4ee50\u662f\u6ca1\u6709\u610f\u4e49\u800c\u4e14\u65e0\u6cd5\u8ba1\u7b97\u7684\uff0c\u5728\u7a0b\u5e8f\u4e2d\u540c\u6837\u662f\u8fd9\u6837<\/p>\n<p>\u5982\u679c\u4f60\u4f7f\u7528\u6574\u578b\u53bb\u96640\uff08\u7c7b\u4f3c\u4e0e15\/0\uff0c0\/0\u7b49\u8ba1\u7b97\uff09\uff0c\uff23\u8bed\u8a00\u6807\u51c6\u4e2d\u5e76\u6ca1\u6709\u5bf9\u6b64\u884c\u4e3a\u7684\u540e\u679c\u505a\u51fa\u89c4\u5b9a\uff08\u672a\u5b9a\u4e49\u884c\u4e3a undefined behavior\uff0c\u7b80\u79f0UB\uff09<\/p>\n<p>\u901a\u5e38\u7684\u540e\u679c\u662f\u9020\u6210\u7a0b\u5e8f\u5d29\u6e83\uff08\u4f60\u53ef\u4ee5\u5199\u4e00\u4e2a\u7a0b\u5e8f\u53bb\u5c1d\u8bd5\uff0c\u5bf9\u4e8e\u73b0\u4ee3\u7684\u7f16\u8bd1\u5668\uff0c\u901a\u5e38\u53ef\u4ee5\u68c0\u67e5\u51fa\u9664\u6570\u4e3a\u5e38\u65700\u7684\u60c5\u51b5\uff0c\u5e76\u7ed9\u51fa\u4e00\u4e2a\u8b66\u544a\uff0c\u5982a\/0\uff0c\u4f46\u662f\u5982\u679c\u9664\u6570\u4e3a\u503c\u4e3a0\u7684\u53d8\u91cf\uff0c\u4fbf\u65e0\u6cd5\u7ed9\u51fa\u8b66\u544a\uff09<\/p>\n<p>\u5bf9\u4e8e\u6d6e\u70b9\u6570\u7684\u9664\u6cd5\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u4f60\u5c06\u5f97\u5230INF\uff0c\u5982\u56fe<\/p>\n<p><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-479\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/1.png\" alt=\"1\" width=\"496\" height=\"84\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/1.png 496w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/1-300x50.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/a><\/p>\n<p>INF\u662finfinity\uff08\u65e0\u7a77\u5927\uff09\u7684\u7f29\u5199\uff0c\u8fd9\u8bf4\u660e\u8fd9\u4e2a\u64cd\u4f5c\u53d1\u751f\u4e86\u6ea2\u51fa\uff0c\u4e0a\u9762\u7684\u7ed3\u679c\u662f\u6b63\u65e0\u7a77\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u4e00\u4e2a\u8d1f\u6570\u4f5c\u4e3a\u88ab\u9664\u6570\uff0c\u90a3\u4e48\u4f60\u5c06\u4f1a\u5f97\u5230\u4e00\u4e2a\u8d1f\u65e0\u7a77\uff08\u4f8b\u5982\u5728-1.#INF00\uff09<\/p>\n<p>INF\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u503c\uff0c\u6b64\u5916\u7c7b\u4f3c\u7684\u503c\u8fd8\u6709IND\uff08infinity \u672a\u5b9a\u4e49\uff09\u7b49<\/p>\n<p>\u6b64\u5916\uff0c\u9664\u6cd5\u8fd0\u7b97\u8fd8\u4f1a\u4ea7\u751f\u4e00\u4e2a\u65b0\u624b\u5bb9\u6613\u72af\u7684\u4e00\u4e2a\u9519\u8bef\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">\u5bf9\u6574\u578b\u4e4b\u95f4\u7684\u9664\u6cd5\uff0c\u7ed3\u679c\u6c38\u8fdc\u662f\u6574\u578b\uff0c\u5bf9\u6d6e\u70b9\u578b\u7684\u6570\u8fdb\u884c\u9664\u6cd5\u8fd0\u7b97\u5c06\u5f97\u5230\u4e00\u4e2a\u6d6e\u70b9\u6570<\/span><\/p>\n<p>\u8fd9\u610f\u5473\u77401\/2\u7684\u503c\u548c1.0\/2.0\u7684\u503c\u662f\u4e0d\u76f8\u540c\u7684\u3002<span style=\"color: #ff0000;\">\u5f53\u6574\u578b\u76f8\u9664\u65e0\u6cd5\u6574\u9664\u65f6\uff08\u59821\/2\uff09\uff0c\u5c0f\u6570\u90e8\u5206\u5c06\u88ab\u4e22\u5f03<\/span>\uff0c\u8fd9\u79cd\u8fc7\u7a0b\u79f0\u4f5c\u201c\u622a\u5c3e\u201d\uff08truncation\uff09<\/p>\n<p>\u8fd9\u610f\u5473\u77401\/2\u7684\u503c\u662f0\uff0c\u800c\u4e0d\u662f0.5\u62161\uff08\u56db\u820d\u4e94\u5165\u7684\u7ed3\u679c\uff09<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u7a0b\u5e8f\u6765\u5b9e\u9a8c<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n\r\nint main()\r\n{\r\n    printf(&quot;3\/2 = %d\\n&quot;, 3 \/ 2);\r\n    printf(&quot;3.0\/2.0 = %lf\\n&quot;, 3.0 \/ 2.0);\r\n    printf(&quot;3\/2.0=%lf\\n&quot;, 3 \/ 2.0);\r\n    printf(&quot;-4\/3=%d&quot;, -3\/2);\r\n    return 0;\r\n}\r\n<\/pre>\n<p><a href=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-480\" src=\"http:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/12.png\" alt=\"12\" width=\"434\" height=\"128\" srcset=\"https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/12.png 434w, https:\/\/yangwang.hk\/wp-content\/uploads\/2015\/08\/12-300x88.png 300w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/a><\/p>\n<p>\u53ef\u4ee5\u770b\u52303\/2\u7ecf\u8fc7\u201c\u622a\u5c3e\u5904\u7406\u201d\u5f97\u5230\u4e861\uff0c\u800c\u503c\u5f97\u6ce8\u610f\u7684\u662f<\/p>\n<p>\u5f53\u4e24\u4e2a\u7c7b\u578b\u4e0d\u540c\u7684\u6570\u76f8\u4e92\u8ba1\u7b97\u65f6\uff0c\u5c06\u8f6c\u6362\u4e3a\u76f8\u540c\u7684\u7c7b\u578b<\/p>\n<p>\u8f6c\u6362\u7684\u65b9\u5411\u901a\u5e38\u662f\u201c\u6269\u5927\u201d\uff0c\u5373\u4e24\u4e2a\u6570\u76f8\u4e92\u8fd0\u7b97\uff0c\u8303\u56f4\u8f83\u5c0f\u7684\u7c7b\u578b\u5c06\u8f6c\u6362\u4e3a\u8303\u56f4\u8f83\u5927\u7684\u7c7b\u578b\uff08\u50a8\u5b58\u8303\u56f4\u5c0f\u7684\u5411\u50a8\u5b58\u8303\u56f4\u5927\u7684\uff0c\u7cbe\u5ea6\u4f4e\u7684\u5411\u7cbe\u5ea6\u9ad8\u7684\uff09<\/p>\n<p>\u5982char\u4e0eint\u76f8\u52a0\uff0c\u4f1a\u5c06char\u8f6c\u6362\u4e3aint\uff0c\u518d\u8fdb\u884c\u6c42\u548c\u8fd0\u7b97\uff0c\u4e0a\u9762\u76843\/3.2\u8fdb\u884c\u8ba1\u7b97\u65f6\uff0c\u4f1a\u5c063\u8fd9\u4e2aint\u7c7b\u578b\u7684\u6570\u5148\u8f6c\u6362\u4e3adouble\u7c7b\u578b\uff0c\u518d\u8fdb\u884c\u9664\u6cd5\u8fd0\u7b97<\/p>\n<p>\u56e0\u6b64\uff0c\u5f97\u5230\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002\u66f4\u591a\u77e5\u8bc6\uff0c\u6211\u4eec\u5c06\u5728\u201c\u7c7b\u578b\u548c\u8f6c\u6362\u4e00\u8282\u5b66\u4e60\u201d<\/p>\n<p>\u53e6\u5916\uff0c\u5728C99\u4ee5\u524d\u7684\u6807\u51c6\u4e2d\uff0c\u5e76\u6ca1\u6709\u5bf9\u7ed3\u679c\u4e3a\u8d1f\u6570\u7684\u6574\u578b\u76f8\u9664\u7684\u5904\u7406\u65b9\u6cd5\u505a\u89c4\u5b9a<\/p>\n<p>\u5982-5\/3\uff0c\u7ed3\u679c\u53ef\u80fd\u662f\u76f4\u63a5\u622a\u5c3e\u7684-1\uff0c\u6216\u662f\u7ed3\u679c\u8fdb\u884c\u56db\u820d\u4e94\u5165\u7684-2\uff08\u56e0\u4e3a-1.666\u56db\u820d\u4e94\u5165\u4e3a-2\uff09<\/p>\n<p>\u4f46\u662fC99\u6807\u51c6\u4e2d\u89c4\u5b9a\u4e86\u8fd9\u4e00\u884c\u4e3a\uff0c\u5904\u7406\u65b9\u6cd5\u4e3a\u76f4\u63a5\u622a\u53bb\u5c0f\u6570\u90e8\u5206<\/p>\n<h3>\u6bd4\u8f83\u8fd0\u7b97\u7b26\u2014\u2014\u201c&lt;\u201d\uff0c\u201c&gt;\u201d\uff0c\u201c==\u201d\uff0c\u201c&lt;=\u201d\uff0c\u201c&gt;=\u201d\uff0c\u201c!=\u201d<\/h3>\n<p>\u6bd4\u8f83\u8fd0\u7b97\u7b26\u5728if\u4e2d\u6211\u4eec\u5df2\u7ecf\u5b66\u8fc7\uff0c\u8fd9\u91cc\u4fbf\u4e0d\u518d\u53d9\u8ff0<\/p>\n<p>\u503c\u5f97\u4e00\u63d0\u7684\u662f\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u8fd4\u56de\u7684\u503c\u662f\u4e00\u4e2aint\u7c7b\u578b<\/p>\n<p>&nbsp;<\/p>\n<p>\u5199\u5230\u8fd9\u91cc\u624d\u53d1\u73b0\u5b57\u6570\u5df2\u7ecf\u78342000\u4e86\uff0c\u4f46\u662fc\u8bed\u8a00\u7684\u8fd0\u7b97\u7b26\u8fd8\u8fdc\u8fdc\u6ca1\u6709\u4ecb\u7ecd\u5b8c\u6bd5\uff0c\u4e8e\u662f\u6211\u5c31\u673a\u667a\u7684\u5728\u6807\u9898\u540e\u52a0\u4e0a\u4e86\u4e00\u4e2a\u201c\u4e0a\u201d\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u7684\u4e0b\u4e00\u7bc7\u6587\u7ae0\uff0c\u4f9d\u7136\u8c08\u7684\u662f\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u5728\u53d8\u91cf\u7684\u8ba1\u7b97\u4e00\u8282\u4e2d\u5df2\u7ecf\u63d0\u5230\u4e86\u8fd0\u7b97\u7b26\u7684\u6982\u5ff5\uff08\u867d\u7136\u4f60\u53ef\u80fd\u5230\u73b0\u5728\u53ea\u7528\u8fc7\u52a0\u51cf\u4e58\u9664\uff09 \u800c\u73b0\u5728\u6211\u4eec\u5c06\u5b66\u4e60c\u8bed\u8a00\u5927\u90e8\u5206\u7684\u2026 <span class=\"read-more\"><a href=\"https:\/\/yangwang.hk\/?p=464\">Read More: 3.4\u3001\u8fd0\u7b97\u7b26\u4e0e\u4f18\u5148\u2026 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-464","post","type-post","status-publish","format-standard","hentry","category-c"],"views":1793,"_links":{"self":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464"}],"version-history":[{"count":5,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/yangwang.hk\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangwang.hk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}