{"id":318,"date":"2020-11-02T16:32:48","date_gmt":"2020-11-02T20:32:48","guid":{"rendered":"http:\/\/www.prglab.com\/blog\/?page_id=318"},"modified":"2020-11-02T16:41:44","modified_gmt":"2020-11-02T20:41:44","slug":"operations","status":"publish","type":"page","link":"https:\/\/www.prglab.com\/blog\/cplusplus-tutorial\/cplusplus-basics\/operations","title":{"rendered":"\u64cd\u4f5c\u8fd0\u7b97"},"content":{"rendered":"\n<h2>1.4 \u64cd\u4f5c\u7b26\/\u8fd0\u7b97\u7b26\uff08Operators\uff09<\/h2>\n\n\n\n<p>\u524d\u9762\u5df2\u7ecf\u5b66\u4e60\u4e86\u53d8\u91cf\u548c\u5e38\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u5bf9\u5b83\u4eec\u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd9\u5c31\u8981\u7528\u5230C++\u7684\u64cd\u4f5c\u7b26\u3002\u6709\u4e9b\u8bed\u8a00\uff0c\u5f88\u591a\u64cd\u4f5c\u7b26\u90fd\u662f\u4e00\u4e9b\u5173\u952e\u5b57\uff0c \u6bd4\u5982add, equals\u7b49\u7b49\u3002C++\u7684\u64cd\u4f5c\u7b26\u4e3b\u8981\u662f\u7531\u7b26\u53f7\u7ec4\u6210\u7684\u3002\u8fd9\u4e9b\u7b26\u53f7\u4e0d\u5728\u5b57\u6bcd\u8868\u4e2d\uff0c\u4f46\u662f\u5728\u6240\u6709\u952e\u76d8\u4e0a\u90fd\u53ef\u4ee5\u627e\u5230\u3002\u8fd9\u4e2a\u7279\u70b9\u4f7f\u5f97C++\u7a0b\u5e8f\u66f4\u7b80\u6d01\uff0c\u4e5f\u66f4\u56fd\u9645\u5316\u3002\u8fd0\u7b97\u7b26\u662fC++\u8bed\u8a00\u7684\u57fa\u7840\uff0c\u6240\u4ee5\u975e\u5e38\u91cd\u8981\u3002<\/p>\n\n\n\n<p>\u4f60\u4e0d\u9700\u8981\u80cc\u4e0b\u6240\u6709\u8fd9\u4e00\u5c0f\u8282\u7684\u5185\u5bb9\uff0c\u8fd9\u4e9b\u7ec6\u8282\u77e5\u8bc6\u4ec5\u4f9b\u4f60\u4ee5\u540e\u9700\u8981\u65f6\u53c2\u8003 \u3002<\/p>\n\n\n\n<h3>\u8d4b\u503cAssignation (=)<\/h3>\n\n\n\n<p>\u8d4b\u503c\u8fd0\u7b97\u7b26\u7684\u529f\u80fd\u662f\u5c06\u4e00\u4e2a\u503c\u8d4b\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3002<code>a = 5;<\/code><\/p>\n\n\n\n<p>\u5c06\u6574\u65705\u8d4b\u7ed9\u53d8\u91cfa\u3002= \u8fd0\u7b97\u7b26\u5de6\u8fb9\u7684\u90e8\u5206\u53eb\u505alvalue (left value)\uff0c\u53f3\u8fb9\u7684\u90e8\u5206\u53eb\u505arvalue (right value)\u3002lvalue \u5fc5\u987b\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u800c\u53f3\u8fb9\u7684\u90e8\u5206\u53ef\u4ee5\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u4e00\u4e2a\u53d8\u91cf\uff0c\u4e00\u4e2a\u8fd0\u7b97(operation)\u7684\u7ed3\u679c\u6216\u662f\u524d\u9762\u51e0\u9879\u7684\u4efb\u610f\u7ec4\u5408\u3002<\/p>\n\n\n\n<p>\u6709\u5fc5\u8981\u5f3a\u8c03\u8d4b\u503c\u8fd0\u7b97\u7b26\u6c38\u8fdc\u662f\u5c06\u53f3\u8fb9\u7684\u503c\u8d4b\u7ed9\u5de6\u8fb9\uff0c\u6c38\u8fdc\u4e0d\u4f1a\u53cd\u8fc7\u6765\u3002<code>a = b;<\/code><\/p>\n\n\n\n<p>\u5c06\u53d8\u91cfb (rvalue)\u7684\u503c\u8d4b\u7ed9\u53d8\u91cfa (lvalue)\uff0c\u4e0d\u8bbaa\u5f53\u65f6\u5b58\u50a8\u7684\u662f\u4ec0\u4e48\u503c\u3002\u540c\u65f6\u8003\u8651\u5230\u6211\u4eec\u53ea\u662f\u5c06b\u7684\u6570\u503c\u8d4b\u7ed9a\uff0c\u4ee5\u540e\u5982\u679cb\u7684\u503c\u6539\u53d8\u4e86\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5230a\u7684\u503c.<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a\u5982\u679c\u6211\u4eec\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801(\u53d8\u91cf\u503c\u7684\u53d8\u5316\u663e\u793a\u5728\u7eff\u8272\u6ce8\u91ca\u90e8\u5206):<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ \u8d4b\u503c\u7b26\u53f7\u4f8b\u5b50<br><br>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main ()<br>{<br>int a, b; \/\/ a:?, b:?<br>a = 10; \/\/ a:10, b:?<br>b = 4; \/\/ a:10, b:4<br>a = b; \/\/ a:4, b:4<br>b = 7; \/\/ a:4, b:7<br><br>cout &lt;&lt; &#8220;a:&#8221;;<br>cout &lt;&lt; a;<br>cout &lt;&lt; &#8221; b:&#8221;;<br>cout &lt;&lt; b;<br><br>return 0;<br>}<\/td><td>a:4 b:7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0a\u4ee3\u7801\u7ed3\u679c\u662fa\u7684\u503c\u4e3a4\uff0c b\u7684\u503c\u4e3a7\u3002\u6700\u540e\u4e00\u884c\u4e2db\u7684\u503c\u88ab\u6539\u53d8\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5230a\uff0c\u867d\u7136\u5728\u6b64\u4e4b\u524d\u6211\u4eec\u58f0\u660e\u4e86a = b; (\u4ece\u53f3\u5230\u5de6\u89c4\u5219right-to-left rule)\u3002<\/p>\n\n\n\n<p>C++\u62e5\u6709\u800c\u5176\u4ed6\u8bed\u8a00\u6ca1\u6709\u7684\u4e00\u4e2a\u7279\u6027\u662f\u8d4b\u503c\u7b26 (=) \u53ef\u4ee5\u88ab\u7528\u4f5c\u53e6\u4e00\u4e2a\u8d4b\u503c\u7b26\u7684rvalue (\u6216rvalue\u7684\u4e00\u90e8\u5206) \u3002\u4f8b\u5982\uff1a<code>a = 2 + (b = 5);<\/code><\/p>\n\n\n\n<p>\u7b49\u540c\u4e8e\uff1a<code>b = 5;<br>a = 2 + b;<\/code><\/p>\n\n\n\n<p>\u5b83\u7684\u610f\u601d\u662f\uff1a\u5148\u5c065\u8d4b\u7ed9\u53d8\u91cfb\uff0c\u7136\u540e\u628a\u524d\u9762\u5bf9b\u7684\u8d4b\u503c\u8fd0\u7b97\u7684\u7ed3\u679c\uff08\u53735\uff09\u52a0\u4e0a2\u518d\u8d4b\u7ed9\u53d8\u91cfa\uff0c\u8fd9\u6837\u6700\u540ea\u4e2d\u7684\u503c\u4e3a7\u3002\u56e0\u6b64\uff0c\u4e0b\u9762\u7684\u8868\u8fbe\u5f0f\u5728C++\u4e2d\u4e5f\u662f\u6b63\u786e\u7684\uff1a<\/p>\n\n\n\n<p>a = b = c = 5;&nbsp;\/\/\u5c065\u540c\u65f6\u8d4b\u7ed93\u4e2a\u53d8\u91cfa, b\u548cc\u3002<\/p>\n\n\n\n<h3>\u6570\u5b66\u8fd0\u7b97\u7b26Arithmetic operators ( +, -, *, \/, % )<\/h3>\n\n\n\n<p>C++\u8bed\u8a00\u652f\u6301\u76845\u79cd\u6570\u5b66\u8fd0\u7b97\u7b26\u4e3a\uff1a<\/p>\n\n\n\n<ul><li>+ \u52a0addition<\/li><li>&#8211; \u51cfsubtraction<\/li><li>* \u4e58multiplication<\/li><li>\/ \u9664division<\/li><li>% \u53d6\u6a21module<\/li><\/ul>\n\n\n\n<p>\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\u60f3\u5fc5\u5927\u5bb6\u90fd\u5f88\u4e86\u89e3\uff0c\u5b83\u4eec\u548c\u4e00\u822c\u7684\u6570\u5b66\u8fd0\u7b97\u7b26\u6ca1\u6709\u533a\u522b\u3002<\/p>\n\n\n\n<p>\u552f\u4e00\u4f60\u53ef\u80fd\u4e0d\u592a\u719f\u6089\u7684\u662f\u7528\u767e\u5206\u53f7(%)\u8868\u793a\u7684\u53d6\u6a21\u8fd0\u7b97\uff08module\uff09\u3002\u53d6\u6a21\u8fd0\u7b97\u662f\u53d6\u4e24\u4e2a\u6574\u6570\u76f8\u9664\u7684\u4f59\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u5199a = 11 % 3;\uff0c\u53d8\u91cfa\u7684\u503c\u5c06\u4f1a\u4e3a\u7ed3\u679c2\uff0c\u56e0\u4e3a2\u662f11\u9664\u4ee53\u7684\u4f59\u6570\u3002<\/p>\n\n\n\n<h3>\u7ec4\u5408\u8fd0\u7b97\u7b26Compound assignation operators (+=, -=, *=, \/=, %=, &gt;&gt;=, &lt;&lt;=, &amp;=, ^=, |=)<\/h3>\n\n\n\n<p>C++\u4ee5\u4e66\u5199\u7b80\u7ec3\u8457\u79f0\u7684\u4e00\u5927\u7279\u8272\u5c31\u662f\u8fd9\u4e9b\u7ec4\u5408\u8fd0\u7b97\u7b26compound assignation operators (+=, -=, *= \u548c \/= \u53ca\u5176\u4ed6) \uff0c\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u4f7f\u5f97\u53ea\u7528\u4e00\u4e2a\u57fa\u672c\u8fd0\u7b97\u7b26\u5c31\u53ef\u6539\u5199\u53d8\u91cf\u7684\u503c\uff1a<\/p>\n\n\n\n<p>value += increase; \u7b49\u540c\u4e8e value = value + increase;<\/p>\n\n\n\n<p>a -= 5; \u7b49\u540c\u4e8e a = a &#8211; 5;<\/p>\n\n\n\n<p>a \/= b; \u7b49\u540c\u4e8e a = a \/ b;<\/p>\n\n\n\n<p>price *= units + 1; \u7b49\u540c\u4e8e price = price * (units + 1);<\/p>\n\n\n\n<p>\u5176\u4ed6\u8fd0\u7b97\u7b26\u4ee5\u6b64\u7c7b\u63a8\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ \u7ec4\u5408\u8fd0\u7b97\u7b26\u4f8b\u5b50<br><br>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main ()<br>{<br>int a, b=3;<br>a = b;<br>a+=2; \/\/ \u76f8\u5f53\u4e8e a=a+2<br>cout &lt;&lt; a;<br>return 0;<br>}<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3>\u9012\u589e\u548c\u9012\u51cfIncrease and decrease<\/h3>\n\n\n\n<p>\u4e66\u5199\u7b80\u7ec3\u7684\u53e6\u4e00\u4e2a\u4f8b\u5b50\u662f\u9012\u589e\uff08increase\uff09\u8fd0\u7b97\u7b26 (++)\u548c\u9012\u51cf\uff08decrease\uff09 \u8fd0\u7b97\u7b26(&#8211;)\u3002\u5b83\u4eec\u4f7f\u5f97\u53d8\u91cf\u4e2d\u5b58\u50a8\u7684\u503c\u52a01\u6216\u51cf1\u3002\u5b83\u4eec\u5206\u522b\u7b49\u540c\u4e8e+=1\u548c-=1\u3002\u56e0\u6b64\uff1a<code>a++;<br>a+=1;<br>a=a+1;<\/code><\/p>\n\n\n\n<p>\u5728\u529f\u80fd\u4e0a\u5168\u90e8\u7b49\u540c\uff0c\u5373\u5168\u90e8\u4f7f\u5f97\u53d8\u91cfa\u7684\u503c\u52a01\u3002<\/p>\n\n\n\n<p>\u5b83\u7684\u5b58\u5728\u662f\u56e0\u4e3a\u6700\u65e9\u7684C\u7f16\u8bd1\u5668\u5c06\u4ee5\u4e0a\u4e09\u79cd\u8868\u8fbe\u5f0f\u7684\u7f16\u8bd1\u6210\u4e0d\u540c\u7684\u673a\u5668\u4ee3\u7801\uff0c\u4e0d\u540c\u7684\u673a\u5668\u4ee3\u7801\u8fd0\u884c\u901f\u5ea6\u4e0d\u4e00\u6837\u3002\u73b0\u5728\uff0c\u7f16\u8bd1\u5668\u5df2\u7ecf\u57fa\u672c\u81ea\u52a8\u5b9e\u884c\u4ee3\u7801\u4f18\u5316\uff0c\u6240\u4ee5\u4ee5\u4e0a\u4e09\u79cd\u4e0d\u540c\u7684\u8868\u8fbe\u65b9\u5f0f\u7f16\u8bd1\u6210\u7684\u673a\u5668\u4ee3\u7801\u5728\u5b9e\u9645\u8fd0\u884c\u4e0a\u5df2\u57fa\u672c\u76f8\u540c\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u8fd0\u7b97\u7b26\u7684\u4e00\u4e2a\u7279\u70b9\u662f\u5b83\u65e2\u53ef\u4ee5\u88ab\u7528\u4f5cprefix\u524d\u7f00\uff0c\u4e5f\u53ef\u4ee5\u88ab\u7528\u4f5c\u540e\u7f00suffix\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b83\u65e2\u53ef\u4ee5\u88ab\u5199\u5728\u53d8\u91cf\u6807\u8bc6\u7684\u524d\u9762(++a)\uff0c\u4e5f\u53ef\u4ee5\u88ab\u5199\u5728\u540e\u9762(a++)\u3002\u867d\u7136\u5728\u7b80\u5355\u8868\u8fbe\u5f0f\u5982a++\u6216++a\u4e2d\uff0c\u8fd9\u4e24\u79cd\u5199\u6cd5\u4ee3\u8868\u540c\u6837\u7684\u610f\u601d\uff0c\u4f46\u5f53\u9012\u589eincrease\u6216\u9012\u51cfdecrease\u7684\u8fd0\u7b97\u7ed3\u679c\u88ab\u76f4\u63a5\u7528\u5728\u5176\u5b83\u7684\u8fd0\u7b97\u5f0f\u4e2d\u65f6\uff0c\u5b83\u4eec\u5c31\u4ee3\u8868\u975e\u5e38\u4e0d\u540c\u7684\u610f\u601d\u4e86\uff1a\u5f53\u9012\u589e\u8fd0\u7b97\u7b26\u88ab\u7528\u4f5c\u524d\u7f00prefix (++a) \u65f6\uff0c\u53d8\u91cfa\u7684\u503c\u7ebf\u589e\u52a0\uff0c\u7136\u540e\u518d\u8ba1\u7b97\u6574\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u56e0\u6b64\u589e\u52a0\u540e\u7684\u503c\u88ab\u7528\u5728\u4e86\u8868\u8fbe\u5f0f\u7684\u8ba1\u7b97\u4e2d\uff1b\u5f53\u5b83\u88ab\u7528\u4f5c\u540e\u7f00suffix (a++)\u65f6\uff0c\u53d8\u91cfa\u7684\u503c\u5728\u8868\u8fbe\u5f0f\u8ba1\u7b97\u540e\u624d\u589e\u52a0\uff0c\u56e0\u6b64a\u5728\u589e\u52a0\u524d\u6240\u5b58\u50a8\u7684\u503c\u88ab\u7528\u5728\u4e86\u8868\u8fbe\u5f0f\u7684\u8ba1\u7b97\u4e2d\u3002\u6ce8\u610f\u4ee5\u4e0b\u4e24\u4e2a\u4f8b\u5b50\u7684\u4e0d\u540c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u4f8b 1<\/th><th>\u4f8b 2<\/th><\/tr><tr><td><code><strong>B=3;<br>A=++B;<br><\/strong>\/\/ A \u7684\u503c\u4e3a 4, B&nbsp;<\/code><code>\u7684\u503c\u4e3a<\/code><code>&nbsp;4<\/code><\/td><td><code><strong>B=3;<br>A=B++;<br><\/strong>\/\/ A&nbsp;<\/code><code>\u7684\u503c\u4e3a<\/code><code>&nbsp;3, B&nbsp;<\/code><code>\u7684\u503c\u4e3a<\/code><code>&nbsp;4<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5728\u7b2c\u4e00\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong>B<\/strong>\u5728\u5b83\u7684\u503c\u88ab\u8d4b\u7ed9<strong>A<\/strong>\u4e4b\u524d\u589e\u52a01\u3002\u800c\u5728\u7b2c\u4e8c\u4e2a\u4f8b\u5b50\u4e2d<strong>B<\/strong>\u539f\u6765\u7684\u503c3\u88ab\u8d4b\u7ed9&nbsp;<strong>A<\/strong>\u7136\u540e<strong>B<\/strong>\u7684\u503c\u624d\u52a01\u53d8\u4e3a4\u3002<\/p>\n\n\n\n<h3>\u5173\u7cfb\u8fd0\u7b97\u7b26Relational operators ( ==, !=, &gt;, &lt;, &gt;=, &lt;= )<\/h3>\n\n\n\n<p>\u6211\u4eec\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26\u6765\u6bd4\u8f83\u4e24\u4e2a\u8868\u8fbe\u5f0f\u3002\u5982ANSI-C++ \u6807\u51c6\u4e2d\u6307\u51fa\u7684\uff0c\u5173\u7cfb\u9884\u7b97\u7684\u7ed3\u679c\u662f\u4e00\u4e2abool\u503c\uff0c\u6839\u636e\u8fd0\u7b97\u7ed3\u679c\u7684\u4e0d\u540c\uff0c\u5b83\u7684\u503c\u53ea\u80fd\u662f\u771f<strong>true<\/strong>\u6216<strong>false<\/strong>\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\u6211\u4eec\u60f3\u901a\u8fc7\u6bd4\u8f83\u4e24\u4e2a\u8868\u8fbe\u5f0f\u6765\u770b\u5b83\u4eec\u662f\u5426\u76f8\u7b49\u6216\u4e00\u4e2a\u503c\u662f\u5426\u6bd4\u53e6\u4e00\u4e2a\u7684\u503c\u5927\u3002\u4ee5\u4e0b\u4e3aC++\u7684\u5173\u7cfb\u8fd0\u7b97\u7b26\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>==<\/td><td>\u76f8\u7b49Equal<\/td><\/tr><tr><td>!=<\/td><td>\u4e0d\u7b49Different<\/td><\/tr><tr><td>&gt;<\/td><td>\u5927\u4e8eGreater than<\/td><\/tr><tr><td>&lt;<\/td><td>\u5c0f\u4e8eLess than<\/td><\/tr><tr><td>&gt;=<\/td><td>\u5927\u4e8e\u7b49\u4e8eGreater or equal than<\/td><\/tr><tr><td>&lt;=<\/td><td>\u5c0f\u4e8e\u7b49\u4e8eLess or equal than<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4e0b\u9762\u4f60\u53ef\u4ee5\u770b\u5230\u4e00\u4e9b\u5b9e\u9645\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>(7 == 5)<\/td><td>\u5c06\u8fd4\u56defalse.<\/td><\/tr><tr><td>(5 &gt; 4)<\/td><td>\u5c06\u8fd4\u56detrue.<\/td><\/tr><tr><td>(3 != 2)<\/td><td>\u5c06\u8fd4\u56detrue.<\/td><\/tr><tr><td>(6 &gt;= 6)<\/td><td>\u5c06\u8fd4\u56detrue.<\/td><\/tr><tr><td>(5 &lt; 5)<\/td><td>\u5c06\u8fd4\u56defalse.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5f53\u7136\uff0c\u9664\u4e86\u4f7f\u7528\u6570\u5b57\u5e38\u91cf\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6709\u6548\u8868\u8fbe\u5f0f\uff0c\u5305\u62ec\u53d8\u91cf\u3002\u5047\u8bbe\u6709a=2, b=3\u548cc=6,<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>(a == 5)<\/td><td>\u5c06\u8fd4\u56defalse.<\/td><\/tr><tr><\/tr><tr><td>(a*b &gt;= c)<\/td><td>\u5c06\u8fd4\u56detrue \u56e0\u4e3a\u5b83\u5b9e\u9645\u662f(2*3 &gt;= 6)<\/td><\/tr><tr><\/tr><tr><td>(b+4 &gt; a*c)<\/td><td>\u5c06\u8fd4\u56defalse\u56e0\u4e3a\u5b83\u5b9e\u9645\u662f(3+4 &gt; 2*6)<\/td><\/tr><tr><\/tr><tr><td>((b=2) == a)<\/td><td>\u5c06\u8fd4\u56detrue.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u6ce8\u610f:<\/strong>\u8fd0\u7b97\u7b26<strong>=<\/strong>&nbsp;(\u5355\u4e2a\u7b49\u53f7)\u4e0d\u540c\u4e8e\u8fd0\u7b97\u7b26<strong>==<\/strong>&nbsp;(\u53cc\u7b49\u53f7)\u3002\u7b2c\u4e00\u4e2a\u662f\u8d4b\u503c\u8fd0\u7b97\u7b26(\u5c06\u7b49\u53f7\u53f3\u8fb9\u7684\u8868\u8fbe\u5f0f\u503c\u8d4b\u7ed9\u5de6\u8fb9\u7684\u53d8\u91cf)\uff1b\u7b2c\u4e8c\u4e2a(==)\u662f\u4e00\u4e2a\u5224\u65ad\u7b49\u4e8e\u7684\u5173\u7cfb\u8fd0\u7b97\u7b26\uff0c\u7528\u6765\u5224\u65ad\u8fd0\u7b97\u7b26\u4e24\u8fb9\u7684\u8868\u8fbe\u5f0f\u662f\u5426\u76f8\u7b49\u3002\u56e0\u6b64\u5728\u4e0a\u9762\u4f8b\u5b50\u4e2d\u6700\u540e\u4e00\u4e2a\u8868\u8fbe\u5f0f((b=2) == a)\uff0c\u6211\u4eec\u9996\u5148\u5c06\u6570\u503c2\u8d4b\u7ed9\u53d8\u91cfb\uff0c\u7136\u540e\u628a\u5b83\u548c\u53d8\u91cfa\u8fdb\u884c\u6bd4\u8f83\u3002\u56e0\u4e3a\u53d8\u91cfa\u4e2d\u5b58\u50a8\u7684\u4e5f\u662f\u6570\u503c2\uff0c\u6240\u4ee5\u6574\u4e2a\u8fd0\u7b97\u7684\u7ed3\u679c\u4e3atrue\u3002<\/p>\n\n\n\n<p><img src=\"http:\/\/www.prglab.com\/cms\/media\/images\/cplusplus\/new-in-ansi.jpg\">\u5728ANSI-C++\u6807\u51c6\u51fa\u73b0\u4e4b\u524d\u7684\u8bb8\u591a\u7f16\u8bd1\u5668\u4e2d\uff0c\u5c31\u50cfC\u8bed\u8a00\u4e2d\uff0c\u5173\u7cfb\u8fd0\u7b97\u5e76\u4e0d\u8fd4\u56de\u503c\u4e3a\u771f<strong>true<\/strong>\u6216\u5047<strong>false<\/strong>\u7684<strong>bool<\/strong>\u503c\uff0c\u800c\u662f\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\u6570\u503c\u6700\u4e3a\u7ed3\u679c\uff0c\u5b83\u7684\u6570\u503c\u53ef\u4ee5\u4e3a<strong>0<\/strong>\uff0c\u4ee3\u8868&#8221;<strong>false<\/strong>&#8220;\u6216\u4e00\u4e2a\u975e<strong>0<\/strong>\u6570\u503c(\u901a\u5e38\u4e3a<strong>1<\/strong>)\u6765\u4ee3\u8868&#8221;<strong>true<\/strong>&#8220;\u3002<\/p>\n\n\n\n<h3>\u903b\u8f91\u8fd0\u7b97\u7b26Logic operators ( !, &amp;&amp;, || )<\/h3>\n\n\n\n<p>\u8fd0\u7b97\u7b26 ! \u7b49\u540c\u4e8e<strong>boolean<\/strong>&nbsp;\u8fd0\u7b97<strong>NOT<\/strong>&nbsp;\uff08\u53d6\u975e\uff09\uff0c\u5b83\u53ea\u6709\u4e00\u4e2a\u64cd\u4f5c\u6570(operand)\uff0c\u5199\u5728\u5b83\u7684\u53f3\u8fb9\u3002\u5b83\u505a\u7684\u552f\u4e00\u5de5\u4f5c\u5c31\u662f\u53d6\u8be5\u64cd\u4f5c\u6570\u7684\u53cd\u9762\u503c\uff0c\u4e5f\u5c31\u662f\u8bf4\u5982\u679c\u64cd\u4f5c\u6570\u503c\u4e3a\u771f<strong>true<\/strong>\uff0c\u90a3\u4e48\u8fd0\u7b97\u540e\u503c\u53d8\u4e3a\u5047<strong>false<\/strong>\uff0c\u5982\u679c\u64cd\u4f5c\u6570\u503c\u4e3a\u5047<strong>false<\/strong>\uff0c\u5219\u8fd0\u7b97\u7ed3\u679c\u4e3a\u771f<strong>true<\/strong>\u3002\u5b83\u5c31\u597d\u50cf\u662f\u8bf4\u53d6\u4e0e\u64cd\u4f5c\u6570\u76f8\u53cd\u7684\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>!(5 == 5)<\/td><td>\u8fd4\u56defalse\uff0c\u56e0\u4e3a\u5b83\u53f3\u8fb9\u7684\u8868\u8fbe\u5f0f(5 == 5)\u4e3a\u771ftrue.<\/td><\/tr><tr><td>!(6 &lt;= 4)<\/td><td>\u8fd4\u56detrue\u56e0\u4e3a(6 &lt;= 4)\u4e3a\u5047false.<\/td><\/tr><tr><td>!true<\/td><td>\u8fd4\u56de\u5047false.<\/td><\/tr><tr><td>!false<\/td><td>\u8fd4\u56de\u771ftrue.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u903b\u8f91\u8fd0\u7b97\u7b26&amp;&amp;\u548c<strong>||<\/strong>\u662f\u7528\u6765\u8ba1\u7b97\u4e24\u4e2a\u8868\u8fbe\u5f0f\u800c\u83b7\u5f97\u4e00\u4e2a\u7ed3\u679c\u503c\u3002\u5b83\u4eec\u5206\u522b\u5bf9\u5e94\u903b\u8f91\u8fd0\u7b97\u4e2d\u7684\u4e0e\u8fd0\u7b97<strong>AND<\/strong>&nbsp;\u548c\u6216\u8fd0\u7b97<strong>OR<\/strong>\u3002\u5b83\u4eec\u7684\u8fd0\u7b97\u7ed3\u679c\u53d6\u51b3\u4e8e\u4e24\u4e2a\u64cd\u4f5c\u6570\uff08operand\uff09\u7684\u5173\u7cfb\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570<br>a<\/th><th>\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570<br>b<\/th><th>\u7ed3\u679c<br>a &amp;&amp; b<\/th><th>\u7ed3\u679c<br>a || b<\/th><\/tr><tr><td>true<\/td><td>true<\/td><td>true<\/td><td>true<\/td><\/tr><tr><td>true<\/td><td>false<\/td><td>false<\/td><td>true<\/td><\/tr><tr><td>false<\/td><td>true<\/td><td>false<\/td><td>true<\/td><\/tr><tr><td>false<\/td><td>false<\/td><td>false<\/td><td>false<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4f8b\u5982 \uff1a( (5 == 5) &amp;&amp; (3 &gt; 6) ) \u8fd4\u56defalse ( true &amp;&amp; false ).<br>( (5 == 5) || (3 &gt; 6)) \u8fd4\u56detrue ( true || false ).<\/p>\n\n\n\n<h3>\u6761\u4ef6\u8fd0\u7b97\u7b26Conditional operator ( ? )<\/h3>\n\n\n\n<p>\u6761\u4ef6\u8fd0\u7b97\u7b26\u8ba1\u7b97\u4e00\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\u5e76\u6839\u636e\u8868\u8fbe\u5f0f\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u771ftrue\u6216\u5047false\u800c\u8fd4\u56de\u4e0d\u540c\u503c\u3002\u5b83\u7684\u683c\u5f0f\u662f\uff1acondition ? result1 : result2 \uff08\u6761\u4ef6\uff1f\u8fd4\u56de\u503c1\uff1a\u8fd4\u56de\u503c2\uff09<\/p>\n\n\n\n<p>\u5982\u679c\u6761\u4ef6condition \u4e3a\u771ftrue\uff0c\u6574\u4e2a\u8868\u8fbe\u5f0f\u5c06\u8fd4\u56deesult1\uff0c\u5426\u5219\u5c06\u8fd4\u56deresult2\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>7==5 ? 4 : 3<\/td><td>\u8fd4\u56de3\uff0c\u56e0\u4e3a7\u4e0d\u7b49\u4e8e5.<\/td><\/tr><tr><td>7==5+2 ? 4 : 3<\/td><td>\u8fd4\u56de4\uff0c\u56e0\u4e3a7\u7b49\u4e8e5+2.<\/td><\/tr><tr><td>5&gt;3 ? a : b<\/td><td>\u8fd4\u56dea\uff0c\u56e0\u4e3a5\u5927\u4e8e3.<\/td><\/tr><tr><td>a&gt;b ? a : b<\/td><td>\u8fd4\u56de\u8f83\u5927\u503c\uff0ca \u6216b.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ \u6761\u4ef6\u8fd0\u7b97\u7b26\u4f8b\u5b50<br><br>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main ()<br>{<br>int a,b,c;<br><br>a=2;<br>b=7;<br>c = (a&gt;b) ? a : b;<br><br>cout &lt;&lt; c;<br><br>return 0;<br>}<\/td><td>7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2da\u7684\u503c\u4e3a2\uff0cb\u7684\u503c\u4e3a7\uff0c\u6240\u4ee5\u8868\u8fbe\u5f0f(a&gt;b)\u8fd0\u7b97\u503c\u4e3a\u5047(false)\uff0c\u6240\u4ee5\u6574\u4e2a\u8868\u8fbe\u5f0f(a&gt;b)?a:b\u8981\u53d6\u5206\u53f7\u540e\u9762\u7684\u503c\uff0c\u4e5f\u5c31\u662fb\u7684\u503c7\u3002\u56e0\u6b64\u6700\u540e\u8f93\u51fa c \u7684\u503c\u4e3a7\u3002<\/p>\n\n\n\n<h3>\u9017\u53f7\u8fd0\u7b97\u7b26 ( , )<\/h3>\n\n\n\n<p>\u9017\u53f7\u8fd0\u7b97\u7b26 (,) \u7528\u6765\u5206\u5f00\u591a\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5e76\u53ea\u53d6\u6700\u53f3\u8fb9\u7684\u8868\u8fbe\u5f0f\u7684\u503c\u8fd4\u56de\u3002<br><br>\u4f8b\u5982\u6709\u4ee5\u4e0b\u4ee3\u7801\uff1aa = (b=3, b+2);<br>\u8fd9\u884c\u4ee3\u7801\u9996\u5148\u5c063\u8d4b\u503c\u7ed9\u53d8\u91cfb\uff0c\u7136\u540e\u5c06&nbsp;b+2&nbsp;\u8d4b\u503c\u7ed9\u53d8\u91cf&nbsp;a\u3002\u6240\u4ee5\u6700\u540e\u53d8\u91cfa&nbsp;\u7684\u503c\u4e3a5\uff0c\u800c\u53d8\u91cfb\u7684\u503c\u4e3a3\u3002<\/p>\n\n\n\n<h3>\u4f4d\u8fd0\u7b97\u7b26Bitwise Operators ( &amp;, |, ^, ~, &lt;&lt;, &gt;&gt; )<\/h3>\n\n\n\n<p>\u4f4d\u8fd0\u7b97\u7b26\u4ee5\u6bd4\u7279\u4f4d\u6539\u5199\u53d8\u91cf\u5b58\u50a8\u7684\u6570\u503c\uff0c\u4e5f\u5c31\u662f\u6539\u5199\u53d8\u91cf\u503c\u7684\u4e8c\u8fdb\u5236\u8868\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>op<\/th><th>asm<\/th><th>Description<\/th><\/tr><tr><td>&amp;<\/td><td>AND<\/td><td>\u903b\u8f91\u4e0e Logic AND<\/td><\/tr><tr><td>|<\/td><td>OR<\/td><td>\u903b\u8f91\u6216Logic OR<\/td><\/tr><tr><td>^<\/td><td>XOR<\/td><td>\u903b\u8f91\u5f02\u6216Logical exclusive OR<\/td><\/tr><tr><td>~<\/td><td>NOT<\/td><td>\u5bf91\u53d6\u8865\uff08\u4f4d\u53cd\u8f6c\uff09Complement to one (bit inversion)<\/td><\/tr><tr><td>&lt;&lt;<\/td><td>SHL<\/td><td>\u5de6\u79fbShift Left<\/td><\/tr><tr><td>&gt;&gt;<\/td><td>SHR<\/td><td>\u53f3\u79fbShift Right<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3>\u53d8\u91cf\u7c7b\u578b\u8f6c\u6362\u8fd0\u7b97\u7b26Explicit type casting operators<\/h3>\n\n\n\n<p>\u53d8\u91cf\u7c7b\u578b\u8f6c\u6362\u8fd0\u7b97\u7b26\u53ef\u4ee5\u5c06\u4e00\u79cd\u7c7b\u578b\u7684\u6570\u636e\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7c7b\u578b\u7684\u6570\u636e\u3002\u5728\u5199C++\u4e2d\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u79cd\u64cd\u4f5c\uff0c\u6700\u5e38\u7528\u7684\u4e00\u79cd\uff0c\u4e5f\u662f\u4e0eC\u517c\u5bb9\u7684\u4e00\u79cd\uff0c\u662f\u5728\u539f\u8f6c\u6362\u7684\u8868\u8fbe\u5f0f\u524d\u9762\u52a0\u7528\u62ec\u53f7()\u62ec\u8d77\u7684\u65b0\u6570\u636e\u7c7b\u578b\uff1aint i;<br>float f = 3.14;<br>i = (int) f;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5c06\u6d6e\u70b9\u578b\u6570\u5b57<strong>3.14<\/strong>\u8f6c\u6362\u6210\u4e00\u4e2a\u6574\u6570\u503c(<strong>3<\/strong>)\u3002\u8fd9\u91cc\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5c\u7b26\u4e3a(<strong>int<\/strong>)\u3002\u5728C++\u4e2d\u5b9e\u73b0\u8fd9\u4e00\u64cd\u4f5c\u7684\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u6784\u9020\u51fd\u6570constructor \u7684\u5f62\u5f0f\uff1a\u5728\u8981\u8f6c\u6362\u7684\u8868\u8fbe\u5f0f\u524d\u52a0\u53d8\u91cf\u7c7b\u578b\u5e76\u5c06\u8868\u8fbe\u5f0f\u62ec\u5728\u62ec\u53f7\u4e2d\uff1ai = int ( f );<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4e24\u79cd\u7c7b\u578b\u8f6c\u6362\u7684\u65b9\u6cd5\u5728C++\u4e2d\u90fd\u662f\u5408\u6cd5\u7684\u3002\u53e6\u5916ANSI-C++\u9488\u5bf9\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08object oriented programming\uff09\u589e\u52a0\u4e86\u65b0\u7684\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5c\u7b26 (\u53c2\u8003<a href=\"http:\/\/www.prglab.com\/cms\/pages\/c-tutorial\/advanced-concepts\/class-type-casting.php\">Section 5.4, Advanced class type-casting<\/a>).<\/p>\n\n\n\n<h3>sizeof()<\/h3>\n\n\n\n<p>\u8fd9\u4e2a\u8fd0\u7b97\u7b26\u63a5\u53d7\u4e00\u4e2a\u8f93\u5165\u53c2\u6570\uff0c\u8be5\u53c2\u6570\u53ef\u4ee5\u662f\u4e00\u4e2a\u53d8\u91cf\u7c7b\u578b\u6216\u4e00\u4e2a\u53d8\u91cf\u81ea\u5df1\uff0c\u8fd4\u56de\u8be5\u53d8\u91cf\u7c7b\u578b(variable type) \u6216\u5bf9\u8c61(object)\u6240\u5360\u7684\u5b57\u8282\u6570\uff1aa = sizeof (char);<\/p>\n\n\n\n<p>\u8fd9\u5c06\u4f1a\u8fd4\u56de1\u7ed9a\uff0c\u56e0\u4e3achar\u662f\u4e00\u4e2a\u5e38\u4e3a1\u4e2a\u5b57\u8282\u7684\u53d8\u91cf\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>sizeof\u8fd4\u56de\u7684\u503c\u662f\u4e00\u4e2a\u5e38\u6570\uff0c\u56e0\u6b64\u5b83\u603b\u662f\u5728\u7a0b\u5e8f\u6267\u884c\u524d\u5c31\u88ab\u56fa\u5b9a\u4e86\u3002<\/p>\n\n\n\n<h3>\u5176\u5b83\u8fd0\u7b97\u7b26<\/h3>\n\n\n\n<p>\u5728\u672c\u6559\u7a0b\u540e\u9762\u7684\u7ae0\u8282\u91cc\u6211\u4eec\u5c06\u770b\u5230\u66f4\u591a\u7684\u8fd0\u7b97\u7b26\uff0c\u6bd4\u5982\u6307\u5411\u6307\u9488\u7684\u8fd0\u7b97\u6216\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7279\u6709\u7684\u8fd0\u7b97\uff0c\u7b49\u7b49\uff0c\u6211\u4eec\u4f1a\u5728\u5b83\u4eec\u5404\u81ea\u7684\u7ae0\u8282\u91cc\u8fdb\u884c\u8be6\u7ec6\u8ba8\u8bba\u3002<\/p>\n\n\n\n<h3>\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u5ea6 Precedence of operators<\/h3>\n\n\n\n<p>\u5f53\u591a\u4e2a\u64cd\u4f5c\u6570\u7ec4\u6210\u590d\u6742\u7684\u8868\u8fbe\u5f0f\u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u7591\u60d1\u54ea\u4e2a\u8fd0\u7b97\u5148\u88ab\u8ba1\u7b97\uff0c\u54ea\u4e2a\u540e\u88ab\u8ba1\u7b97\u3002\u4f8b\u5982\u4ee5\u4e0b\u8868\u8fbe\u5f0f\uff1a<code>a = 5 + 7 % 2<\/code><\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u6000\u7591\u5b83\u5b9e\u9645\u4e0a\u8868\u793a\uff1a<\/p>\n\n\n\n<p>a = 5 + (7 % 2) \u7ed3\u679c\u4e3a<strong>6<\/strong>\uff0c\u8fd8\u662f a = (5 + 7) % 2 \u7ed3\u679c\u4e3a<strong>0<\/strong>?<\/p>\n\n\n\n<p>\u6b63\u786e\u7b54\u6848\u4e3a\u7b2c\u4e00\u4e2a\uff0c\u7ed3\u679c\u4e3a6\u3002\u6bcf\u4e00\u4e2a\u8fd0\u7b97\u7b26\u6709\u4e00\u4e2a\u56fa\u5b9a\u7684\u4f18\u5148\u7ea7\uff0c\u4e0d\u4ec5\u5bf9\u6570\u5b66\u8fd0\u7b97\u7b26\uff08\u6211\u4eec\u53ef\u80fd\u5728\u5b66\u4e60\u6570\u5b66\u7684\u65f6\u5019\u5df2\u7ecf\u5f88\u4e86\u89e3\u5b83\u4eec\u7684\u4f18\u5148\u987a\u5e8f\u4e86\uff09\uff0c\u6240\u6709\u5728C++\u4e2d\u51fa\u73b0\u7684\u8fd0\u7b97\u7b26\u90fd\u6709\u4f18\u5148\u7ea7\u3002\u4ece\u6700\u4ece\u6700\u9ad8\u7ea7\u5230\u6700\u4f4e\u7ea7\uff0c\u8fd0\u7b97\u7684\u4f18\u5148\u7ea7\u6309\u4e0b\u8868\u6392\u5217\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u4f18\u5148\u7ea7<br>Level<\/th><th>\u64cd\u4f5c\u7b26<br>Operator<\/th><th>\u8bf4\u660e<br>Description<\/th><th>\u7ed3\u5408\u65b9\u5411<br>Grouping<\/th><\/tr><tr><td>1<\/td><td>::<\/td><td>\u8303\u56f4<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>2<\/td><td>() [] . -&gt; ++ &#8212; dynamic_cast static_cast reinterpret_cast const_cast typeid<\/td><td>\u540e\u7f00<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td rowspan=\"3\">3<\/td><td>++ &#8212; ~ ! sizeof new delete<\/td><td>\u4e00\u5143(\u524d\u7f00)<\/td><td rowspan=\"3\">\u4ece\u53f3\u5230\u5de6<\/td><\/tr><tr><td>* &amp;<\/td><td>\u6307\u9488\u548c\u53d6\u5730\u5740<\/td><\/tr><tr><td>+ &#8211;<\/td><td>\u4e00\u5143\u7b26\u53f7<\/td><\/tr><tr><td>4<\/td><td>(type)<\/td><td>\u7c7b\u578b\u8f6c\u6362<\/td><td>\u4ece\u53f3\u5230\u5de6<\/td><\/tr><tr><td>5<\/td><td>.* -&gt;*<\/td><td>\u6307\u5411\u6210\u5458\u7684\u6307\u9488<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>6<\/td><td>* \/ %<\/td><td>\u4e58\u3001\u9664\u3001\u53d6\u6a21<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>7<\/td><td>+ &#8211;<\/td><td>\u52a0\u51cf<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>8<\/td><td>&lt;&lt; &gt;&gt;<\/td><td>\u4f4d\u79fb<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>9<\/td><td>&lt; &gt; &lt;= &gt;=<\/td><td>\u5173\u7cfb\u64cd\u4f5c\u7b26<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>10<\/td><td>== !=<\/td><td>\u7b49\u4e8e\u3001\u4e0d\u7b49\u4e8e<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>11<\/td><td>&amp;<\/td><td>\u6309\u4f4d\u4e0e\u8fd0\u7b97<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>12<\/td><td>^<\/td><td>\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>13<\/td><td>|<\/td><td>\u6309\u4f4d\u6216\u8fd0\u7b97<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>14<\/td><td>&amp;&amp;<\/td><td>\u903b\u8f91\u4e0e\u8fd0\u7b97<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>15<\/td><td>||<\/td><td>\u903b\u8f91\u6216\u8fd0\u7b97<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><tr><td>16<\/td><td>?:<\/td><td>\u6761\u4ef6\u8fd0\u7b97<\/td><td>\u4ece\u53f3\u5230\u5de6<\/td><\/tr><tr><td>17<\/td><td>= *= \/= %= += -= &gt;&gt;= &lt;&lt;= &amp;= ^= |=<\/td><td>\u8d4b\u503c\u8fd0\u7b97<\/td><td>\u4ece\u53f3\u5230\u5de6<\/td><\/tr><tr><td>18<\/td><td>,<\/td><td>\u9017\u53f7<\/td><td>\u4ece\u5de6\u5230\u53f3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u7ed3\u5408\u65b9\u5411Grouping\u5b9a\u4e49\u4e86\u5f53\u6709\u540c\u4f18\u5148\u7ea7\u7684\u591a\u4e2a\u8fd0\u7b97\u7b26\u5728\u4e00\u8d77\u65f6\uff0c\u54ea\u4e00\u4e2a\u5fc5\u987b\u88ab\u9996\u5148\u8fd0\u7b97\uff0c\u6700\u53f3\u8fb9\u7684\u8fd8\u662f\u6700\u5de6\u8fb9\u7684\u3002<\/p>\n\n\n\n<p>\u6240\u6709\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7\u987a\u5e8f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u62ec\u53f7parenthesis signs (\u548c)\u6765\u63a7\u5236\uff0c\u800c\u4e14\u66f4\u6613\u8bfb\u61c2\uff0c\u4f8b\u5982\u4ee5\u4e0b\u4f8b\u5b50\uff1a<code>a = 5 + 7 % 2;<\/code><\/p>\n\n\n\n<p>\u6839\u636e\u6211\u4eec\u60f3\u8981\u5b9e\u73b0\u7684\u8ba1\u7b97\u7684\u4e0d\u540c\uff0c\u53ef\u4ee5\u5199\u6210\uff1a<code>a = 5 + (7 % 2); \u6216\u8005<br>a = (5 + 7) % 2;<\/code><\/p>\n\n\n\n<p>\u6240\u4ee5\u5982\u679c\u4f60\u60f3\u5199\u4e00\u4e2a\u590d\u6742\u7684\u8868\u8fbe\u5f0f\u4f46\u662f\u4e0d\u592a\u786e\u5b9a\u5404\u4e2a\u8fd0\u7b97\u7684\u6267\u884c\u987a\u5e8f\uff0c\u5c31\u5efa\u8bae\u52a0\u4e0a\u62ec\u53f7\u3002\u8fd9\u6837\u8fd8\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u6613\u8bfb\u61c2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.4 \u64cd\u4f5c\u7b26\/\u8fd0\u7b97\u7b26\uff08Operators\uff09 \u524d\u9762\u5df2\u7ecf\u5b66\u4e60\u4e86\u53d8\u91cf\u548c\u5e38\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u5bf9\u5b83\u4eec\u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd9\u5c31\u8981\u7528\u5230C++\u7684\u64cd\u4f5c\u7b26\u3002\u6709\u4e9b\u8bed\u8a00\uff0c\u5f88\u591a\u64cd\u4f5c\u7b26\u90fd\u662f\u4e00\u4e9b\u5173\u952e\u5b57\uff0c \u6bd4\u5982add, equals\u7b49\u7b49\u3002C++\u7684\u64cd\u4f5c\u7b26\u4e3b\u8981\u662f\u7531\u7b26\u53f7\u7ec4\u6210\u7684\u3002\u8fd9\u4e9b\u7b26\u53f7\u4e0d\u5728\u5b57\u6bcd\u8868\u4e2d\uff0c\u4f46\u662f\u5728\u6240\u6709\u952e\u76d8\u4e0a\u90fd\u53ef\u4ee5\u627e\u5230\u3002\u8fd9\u4e2a\u7279\u70b9\u4f7f\u5f97C++\u7a0b\u5e8f\u66f4\u7b80\u6d01\uff0c\u4e5f\u66f4\u56fd\u9645\u5316\u3002\u8fd0\u7b97\u7b26\u662fC++\u8bed\u8a00\u7684\u57fa\u7840\uff0c\u6240\u4ee5\u975e\u5e38\u91cd\u8981\u3002 \u4f60\u4e0d\u9700\u8981\u80cc\u4e0b\u6240\u6709\u8fd9\u4e00\u5c0f\u8282\u7684\u5185\u5bb9\uff0c\u8fd9\u4e9b\u7ec6\u8282\u77e5\u8bc6\u4ec5\u4f9b\u4f60\u4ee5\u540e\u9700\u8981\u65f6\u53c2\u8003 \u3002 \u8d4b\u503cAssignation (=) \u8d4b\u503c\u8fd0\u7b97\u7b26\u7684\u529f\u80fd\u662f\u5c06\u4e00\u4e2a\u503c\u8d4b\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3002a = 5; \u5c06\u6574\u65705\u8d4b\u7ed9\u53d8\u91cfa\u3002= \u8fd0\u7b97\u7b26\u5de6\u8fb9\u7684\u90e8\u5206\u53eb\u505alvalue (left value)\uff0c\u53f3\u8fb9\u7684\u90e8\u5206\u53eb\u505arvalue (right value)\u3002lvalue \u5fc5\u987b\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u800c\u53f3\u8fb9\u7684\u90e8\u5206\u53ef\u4ee5\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u4e00\u4e2a\u53d8\u91cf\uff0c\u4e00\u4e2a\u8fd0\u7b97(operation)\u7684\u7ed3\u679c\u6216\u662f\u524d\u9762\u51e0\u9879\u7684\u4efb\u610f\u7ec4\u5408\u3002 \u6709\u5fc5\u8981\u5f3a\u8c03\u8d4b\u503c\u8fd0\u7b97\u7b26\u6c38\u8fdc\u662f\u5c06\u53f3\u8fb9\u7684\u503c\u8d4b\u7ed9\u5de6\u8fb9\uff0c\u6c38\u8fdc\u4e0d\u4f1a\u53cd\u8fc7\u6765\u3002a = b; \u5c06\u53d8\u91cfb (rvalue)\u7684\u503c\u8d4b\u7ed9\u53d8\u91cfa (lvalue)\uff0c\u4e0d\u8bbaa\u5f53\u65f6\u5b58\u50a8\u7684\u662f\u4ec0\u4e48\u503c\u3002\u540c\u65f6\u8003\u8651\u5230\u6211\u4eec\u53ea\u662f\u5c06b\u7684\u6570\u503c\u8d4b\u7ed9a\uff0c\u4ee5\u540e\u5982\u679cb\u7684\u503c\u6539\u53d8\u4e86\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5230a\u7684\u503c. \u4f8b\u5982\uff1a\u5982\u679c\u6211\u4eec\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801(\u53d8\u91cf\u503c\u7684\u53d8\u5316\u663e\u793a\u5728\u7eff\u8272\u6ce8\u91ca\u90e8\u5206): \/\/ \u8d4b\u503c\u7b26\u53f7\u4f8b\u5b50 #include &lt;iostream&gt;using namespace std; int main (){int a, b; \/\/ a:?, b:?a = 10; \/\/ a:10, b:?b = 4; \/\/ a:10, b:4a = b; \/\/ a:4, b:4b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":309,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/318"}],"collection":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/comments?post=318"}],"version-history":[{"count":3,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/318\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/318\/revisions\/322"}],"up":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/309"}],"wp:attachment":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/media?parent=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}