{"id":313,"date":"2020-11-02T11:55:50","date_gmt":"2020-11-02T15:55:50","guid":{"rendered":"http:\/\/www.prglab.com\/blog\/?page_id=313"},"modified":"2020-11-02T11:55:50","modified_gmt":"2020-11-02T15:55:50","slug":"variables-data-types","status":"publish","type":"page","link":"https:\/\/www.prglab.com\/blog\/cplusplus-tutorial\/cplusplus-basics\/variables-data-types","title":{"rendered":"\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"\n<h2>1.2 \u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b \uff08Variables and Data types \uff09<\/h2>\n\n\n\n<p>\u4f60\u53ef\u80fd\u89c9\u5f97\u8fd9\u4e2a\u201cHellow World\u201d\u7a0b\u5e8f\u7528\u5904\u4e0d\u5927\u3002\u6211\u4eec\u5199\u4e86\u597d\u51e0\u884c\u4ee3\u7801\uff0c\u7f16\u8bd1\uff0c\u7136\u540e\u6267\u884c\u751f\u6210\u7684\u7a0b\u5e8f\u53ea\u662f\u4e3a\u4e86\u5728\u5c4f\u5e55\u4e0a\u770b\u5230\u4e00\u53e5\u8bdd\u3002\u7684\u786e\uff0c\u6211\u4eec\u76f4\u63a5\u5728\u5c4f\u5e55\u4e0a\u6253\u51fa\u8fd9\u53e5\u8bdd\u4f1a\u66f4\u5feb\u3002\u4f46\u662f\u7f16\u7a0b\u5e76\u4e0d\u4ec5\u9650\u4e8e\u5728\u5c4f\u5e55\u4e0a\u6253\u51fa\u6587\u5b57\u8fd9\u4e48\u7b80\u5355\u7684\u5de5\u4f5c\u3002\u4e3a\u4e86\u80fd\u591f\u8fdb\u4e00\u6b65\u5199\u51fa\u53ef\u4ee5\u6267\u884c\u66f4\u6709\u7528\u7684\u4efb\u52a1\u7684\u7a0b\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u5f15\u5165<strong>\u53d8\u91cf\uff08variable\uff09<\/strong>\u8fd9\u4e2a\u7684\u6982\u5ff5\u3002<\/p>\n\n\n\n<p>\u8ba9\u6211\u4eec\u8bbe\u60f3\u8fd9\u6837\u4e00\u4e2a\u4f8b\u5b50\uff0c\u6211\u8981\u6c42\u4f60\u5728\u8111\u5b50\u91cc\u8bb0\u4f4f5\u8fd9\u4e2a\u6570\u5b57\uff0c\u7136\u540e\u518d\u8bb0\u4f4f2\u8fd9\u4e2a\u6570\u5b57\u3002\u4f60\u5df2\u7ecf\u5b58\u50a8\u4e86\u4e24\u4e2a\u6570\u503c\u5728\u4f60\u7684\u8bb0\u5fc6\u91cc\u3002\u73b0\u5728\u6211\u8981\u6c42\u4f60\u5728\u6211\u8bf4\u7684\u7b2c\u4e00\u4e2a\u6570\u503c\u4e0a\u52a01\uff0c\u4f60\u5e94\u8be5\u4fdd\u75596 \uff08\u53735+1\uff09\u548c2\u5728\u4f60\u7684\u8bb0\u5fc6\u91cc\u3002\u73b0\u5728\u5982\u679c\u6211\u4eec\u5c06\u4e24\u6570\u76f8\u51cf\u53ef\u4ee5\u5f97\u5230\u7ed3\u679c4\u3002<\/p>\n\n\n\n<p>\u6240\u6709\u8fd9\u4e9b\u4f60\u5728\u8111\u5b50\u91cc\u505a\u7684\u4e8b\u60c5\u4e0e\u8ba1\u7b97\u673a\u7528\u4e24\u4e2a\u53d8\u91cf\u53ef\u4ee5\u505a\u7684\u4e8b\u60c5\u975e\u5e38\u76f8\u4f3c\u3002\u540c\u6837\u7684\u5904\u7406\u8fc7\u7a0b\u7528C++\u6765\u8868\u793a\u53ef\u4ee5\u5199\u6210\u4e0b\u9762\u4e00\u6bb5\u4ee3\u7801\uff1aa = 5;<br>b = 2;<br>a = a + 1;<br>result = a &#8211; b;<\/p>\n\n\n\n<p>\u5f88\u660e\u663e\u8fd9\u662f\u4e00\u4e2a\u5f88\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u7528\u4e86\u4e24\u4e2a\u5c0f\u7684\u6574\u6570\u6570\u503c\u3002\u4f46\u662f\u60f3\u4e00\u60f3\u4f60\u7684\u7535\u8111\u53ef\u4ee5\u540c\u65f6\u5b58\u50a8\u6210\u5343\u4e0a\u4e07\u8fd9\u6837\u7684\u6570\u503c\uff0c\u5e76\u8fdb\u884c\u590d\u6742\u7684\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06<strong>\u53d8\u91cf\uff08variable\uff09<\/strong>\u5b9a\u4e49\u4e3a\u5185\u5b58\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4ee5\u5b58\u50a8\u4e00\u4e2a\u786e\u5b9a\u7684\u503c\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e00\u4e2a\u53d8\u91cf (variable)\u9700\u8981\u4e00\u4e2a\u6807\u8bc6\uff0c\u4ee5\u4fbf\u5c06\u5b83\u4e0e\u5176\u4ed6\u53d8\u91cf\u76f8\u533a\u522b\uff0c\u4f8b\u5982\uff0c\u5728\u524d\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u53d8\u91cf\u6807\u8bc6\u662f<strong>a, b,<\/strong>&nbsp;\u548c<strong>result<\/strong>\u3002\u6211\u4eec\u53ef\u4ee5\u7ed9\u53d8\u91cf\u8d77\u4efb\u4f55\u540d\u5b57\uff0c\u53ea\u8981\u5b83\u4eec\u662f\u6709\u6548\u7684\u6807\u8bc6\u7b26\u3002<\/p>\n\n\n\n<h3>\u6807\u8bc6\uff08Identifiers\uff09<\/h3>\n\n\n\n<p>\u6709\u6548\u6807\u8bc6\u7531\u5b57\u6bcd(letter)\uff0c\u6570\u5b57(digits)\u548c\u4e0b\u5212\u7ebf ( _ )\u7ec4\u6210\u3002\u6807\u8bc6\u7684\u957f\u5ea6\u6ca1\u6709\u9650\u5236\uff0c\u4f46\u662f\u6709\u4e9b\u7f16\u8bd1\u5668\u53ea\u53d6\u524d32\u4e2a\u5b57\u7b26\uff08\u5269\u4e0b\u7684\u5b57\u7b26\u4f1a\u88ab\u5ffd\u7565\uff09\u3002<\/p>\n\n\n\n<p>\u7a7a\u683c(spaces)\uff0c\u6807\u70b9(punctuation marks)\u548c\u7b26\u53f7(symbols) \u90fd\u4e0d\u53ef\u4ee5\u51fa\u73b0\u5728\u6807\u8bc6\u4e2d\u3002 \u53ea\u6709\u5b57\u6bcd(letters)\uff0c\u6570\u5b57(digits) \u548c\u4e0b\u5212\u7ebf(_)\u662f\u5408\u6cd5\u7684\u3002\u5e76\u4e14\u53d8\u91cf\u6807\u8bc6\u5fc5\u987b\u4ee5\u5b57\u6bcd\u5f00\u5934\u3002\u6807\u8bc6\u4e5f\u53ef\u80fd\u4ee5\u4e0b\u5212\u7ebf\uff08_\uff09\u5f00\u5934\uff0c\u4f46\u8fd9\u79cd\u6807\u8bc6\u901a\u5e38\u662f\u4fdd\u7559\u7ed9\u4e3a\u5916\u90e8\u8fde\u63a5\u7528\u7684\u3002\u6807\u8bc6\u4e0d\u53ef\u4ee5\u4ee5\u6570\u5b57\u5f00\u5934\u3002<\/p>\n\n\n\n<p>\u5fc5\u987b\u6ce8\u610f\u7684\u53e6\u4e00\u6761\u89c4\u5219\u662f\u5f53\u4f60\u7ed9\u53d8\u91cf\u8d77\u540d\u5b57\u65f6\u4e0d\u53ef\u4ee5\u548cC++\u8bed\u8a00\u7684<strong>\u5173\u952e\u5b57<\/strong>\u6216\u4f60\u6240\u4f7f\u7528\u7684\u7f16\u8bd1\u5668\u7684<strong>\u7279\u6b8a\u5173\u952e\u5b57<\/strong>\u540c\u540d\uff0c\u56e0\u4e3a\u8fd9\u6837\u4e0e\u8fd9\u4e9b\u5173\u952e\u5b57\u4ea7\u751f\u6df7\u6dc6\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u5217\u51fa\u6807\u51c6\u4fdd\u7559\u5173\u952e\u5b57\uff0c\u4ed6\u4eec\u4e0d\u5141\u8bb8\u88ab\u7528\u4f5c\u53d8\u91cf\u6807\u8bc6\u540d\u79f0\uff1a<\/p>\n\n\n\n<p><code><strong>asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while<\/strong><\/code><\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u4e0d\u8981\u4f7f\u7528\u4e00\u4e9b\u64cd\u4f5c\u7b26\u7684\u66ff\u4ee3\u8868\u793a\u4f5c\u4e3a\u53d8\u91cf\u6807\u8bc6\uff0c\u56e0\u4e3a\u5728\u67d0\u4e9b\u73af\u5883\u4e2d\u5b83\u4eec\u53ef\u80fd\u88ab\u7528\u4f5c\u4fdd\u7559\u8bcd\uff1a<\/p>\n\n\n\n<p><code><strong>and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq<\/strong><\/code><\/p>\n\n\n\n<p>\u4f60\u7684\u7f16\u8bd1\u5668\u8fd8\u53ef\u80fd\u5305\u542b\u4e00\u4e9b\u7279\u6b8a\u4fdd\u7559\u8bcd\uff0c\u4f8b\u5982\u8bb8\u591a\u751f\u621016\u4f4d\u7801\u7684\u7f16\u8bd1\u5668\uff08\u6bd4\u5982\u4e00\u4e9bDOS\u7f16\u8bd1\u5668\uff09\u628a far, huge\u548c near\u4e5f\u4f5c\u4e3a\u5173\u952e\u5b57\u3002<\/p>\n\n\n\n<p><strong>\u975e\u5e38\u91cd\u8981\uff1a<\/strong>C++\u8bed\u8a00\u662f\u201c \u5927\u5c0f\u5199\u654f\u611f\u201d(\u201ccase sensitive\u201d) \u7684\uff0c\u5373\u540c\u6837\u7684\u540d\u5b57\u5b57\u6bcd\u5927\u5c0f\u5199\u4e0d\u540c\u4ee3\u8868\u4e0d\u540c\u7684\u53d8\u91cf\u6807\u8bc6\u3002\u56e0\u6b64\uff0c\u4f8b\u5982\u53d8\u91cf<strong>RESULT<\/strong>\uff0c\u53d8\u91cf<strong>result<\/strong>\u548c\u53d8\u91cf<strong>Result<\/strong>\u5206\u522b\u8868\u793a\u4e09\u4e2a\u4e0d\u540c\u7684\u53d8\u91cf\u6807\u8bc6.<\/p>\n\n\n\n<h3>\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff08Fundamental Data types\uff09<\/h3>\n\n\n\n<p>\u7f16\u7a0b\u65f6\u6211\u4eec\u5c06\u53d8\u91cf\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u7684\u5185\u5b58\u4e2d\uff0c\u4f46\u662f\u8ba1\u7b97\u673a\u8981\u77e5\u9053\u6211\u4eec\u8981\u7528\u8fd9\u4e9b\u53d8\u91cf\u5b58\u50a8\u4ec0\u4e48\u6837\u7684\u503c\uff0c\u56e0\u4e3a\u4e00\u4e2a\u7b80\u5355\u7684\u6570\u503c\uff0c\u4e00\u4e2a\u5b57\u7b26\uff0c\u6216\u4e00\u4e2a\u5de8\u5927\u7684\u6570\u503c\u5728\u5185\u5b58\u6240\u5360\u7528\u7684\u7a7a\u95f4\u662f\u4e0d\u4e00\u6837\u7684\u3002<\/p>\n\n\n\n<p>\u8ba1\u7b97\u673a\u7684\u5185\u5b58\u662f\u4ee5\u5b57\u8282(byte)\u4e3a\u5355\u4f4d\u7ec4\u7ec7\u7684\u3002\u4e00\u4e2a\u5b57\u8282\uff08byte\uff09\u662f\u6211\u4eec\u5728C++\u4e2d\u80fd\u591f\u64cd\u4f5c\u7684\u6700\u5c0f\u7684\u5185\u5b58\u5355\u4f4d\u3002\u4e00\u4e2a\u5b57\u8282(byte)\u53ef\u4ee5\u5b58\u50a8\u76f8\u5bf9\u8f83\u5c0f\u6570\u636e\uff1a\u4e00\u4e2a\u5355\u4e2a\u7684\u5b57\u7b26\u6216\u4e00\u4e2a\u5c0f\u6574\u6570\uff08\u901a\u5e38\u4e3a\u4e00\u4e2a0\u5230255\u4e4b\u95f4\u7684\u6574\u6570\uff09\u3002\u4f46\u662f\u8ba1\u7b97\u673a\u53ef\u4ee5\u540c\u65f6\u64cd\u4f5c\u5904\u7406\u7531\u591a\u4e2a\u5b57\u8282\u7ec4\u6210\u590d\u6742\u6570\u636e\u7c7b\u578b\uff0c\u6bd4\u5982\u957f\u6574\u6570(long integers)\u548c\u5c0f\u6570\uff08decimals\uff09\u3002\u4ee5\u4e0b\u5217\u8868\u603b\u7ed3\u4e86\u73b0\u6709\u7684C++\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u4ee5\u53ca\u6bcf\u4e00\u7c7b\u578b\u6240\u80fd\u5b58\u50a8\u7684\u6570\u636e\u8303\u56f4\uff1a<\/p>\n\n\n\n<p><strong>\u6570\u636e\u7c7b\u578b\uff08DATA TYPES\uff09<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u540d\u79f0<\/th><th>\u5b57\u8282\u6570*<\/th><th>\u63cf\u8ff0<\/th><th>\u8303\u56f4*<\/th><\/tr><tr><td><strong>char<\/strong><\/td><td>1<\/td><td>\u5b57\u7b26\uff08character\uff09\u6216\u6574\u6570\uff08integer \uff09\uff0c 8\u4f4d\uff08bits\uff09\u957f<\/td><td><strong>\u6709\u7b26\u53f7\uff08signed\uff09:<\/strong>&nbsp;-128 \u5230 127<br><strong>\u65e0\u7b26\u53f7\uff08unsigned\uff09:<\/strong>&nbsp;0 \u5230 255<\/td><\/tr><tr><td><strong>short int (short)<\/strong><\/td><td>2<\/td><td>\u77ed\u6574\u6570\uff08integer \uff0916\u4f4d\uff08bits\uff09\u957f<\/td><td><strong>\u6709\u7b26\u53f7\uff08signed\uff09:<\/strong>&nbsp;-32768 \u5230 32767<br><strong>\u65e0\u7b26\u53f7\uff08unsigned\uff09:<\/strong>&nbsp;0 \u5230 65535<\/td><\/tr><tr><td><strong>long int (long)<\/strong><\/td><td>4<\/td><td>\u957f\u6574\u6570\uff08integer \uff0932\u4f4d\uff08bits\uff09\u957f<\/td><td><strong>\u6709\u7b26\u53f7\uff08signed\uff09:<\/strong>-2147483648 \u5230 2147483647<br><strong>\u65e0\u7b26\u53f7\uff08unsigned\uff09:<\/strong>&nbsp;0 \u5230 4294967295<\/td><\/tr><tr><td><strong>int<\/strong><\/td><td>4<\/td><td>\u6574\u6570\uff08integer\uff09<\/td><td><strong>\u6709\u7b26\u53f7(signed):&nbsp;<\/strong>-2147483648 \u5230 2147483647<strong><br>\u65e0\u7b26\u53f7\uff08unsigned):&nbsp;<\/strong>0 \u5230 4294967295&nbsp;<\/td><\/tr><tr><td><strong>float<\/strong><\/td><td>4<\/td><td>\u6d6e\u70b9\u6570\uff08floating point number\uff09<\/td><td>3.4e + \/ &#8211; 38 \uff087 \u4e2a\u6570\u5b57\uff087digits\uff09\uff09<\/td><\/tr><tr><td><strong>double<\/strong><\/td><td>8<\/td><td>\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff08double precision floating point number\uff09<\/td><td>1.7e + \/ &#8211; 308 (15 digits)<\/td><\/tr><tr><td>long double<\/td><td>8<\/td><td>\u957f\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff08long double precision floating point number\uff09<\/td><td>1.7e + \/ &#8211; 308 (15 digits)<\/td><\/tr><tr><td>bool<\/td><td>1<\/td><td>\u5e03\u5c14Boolean\u503c\u3002\u5b83\u53ea\u80fd\u662f\u771f(true)\u6216\u5047(false)\u4e24\u503c\u4e4b\u4e00\u3002<\/td><td><strong>true<\/strong>&nbsp;\u6216&nbsp;<strong>false<\/strong><\/td><\/tr><tr><td>wchar_t<\/td><td>2<\/td><td>\u5bbd\u5b57\u7b26(Wide character) \u3002\u8fd9\u662f\u4e3a\u5b58\u50a8\u4e24\u5b57\u8282(2 bytes) \u957f\u7684\u56fd\u9645\u5b57\u7b26\u800c\u8bbe\u8ba1\u7684\u7c7b\u578b\u3002<\/td><td>\u4e00\u4e2a\u5bbd\u5b57\u7b26\uff081 wide characters\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>*<\/strong>&nbsp;\u5b57\u8282\u6570\u4e00\u5217\u548c\u8303\u56f4\u4e00\u5217\u53ef\u80fd\u6839\u636e\u7a0b\u5e8f\u7f16\u8bd1\u548c\u8fd0\u884c\u7684\u7cfb\u7edf\u4e0d\u540c\u800c\u6709\u6240\u4e0d\u540c\u3002\u8fd9\u91cc\u5217\u51fa\u7684\u6570\u503c\u662f\u591a\u657032\u4f4d\u7cfb\u7edf\u7684\u5e38\u7528\u6570\u636e\u3002\u5bf9\u4e8e\u5176\u4ed6\u7cfb\u7edf\uff0c\u901a\u5e38\u7684\u8bf4\u6cd5\u662f\u6574\u578b(int)\u5177\u6709\u6839\u636e\u7cfb\u7edf\u7ed3\u6784\u5efa\u8bae\u7684\u81ea\u7136\u957f\u5ea6\uff08\u5373\u4e00\u4e2a\u5b57one word\u7684\u957f\u5ea6\uff09\uff0c\u800c4\u4e2d\u6574\u578b\u6570\u636echar, short, int, long\u7684\u957f\u5ea6\u5fc5\u987b\u662f\u9012\u589e\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u6309\u987a\u5e8f\u6bcf\u4e00\u7c7b\u578b\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e\u5176\u524d\u9762\u4e00\u4e2a\u7c7b\u578b\u7684\u957f\u5ea6\u3002\u540c\u6837\u7684\u89c4\u5219\u4e5f\u9002\u7528\u4e8e\u6d6e\u70b9\u6570\u7c7b\u578bfloat, double\u548c long double\uff0c\u4e5f\u662f\u6309\u9012\u589e\u987a\u5e8f\u3002<\/p>\n\n\n\n<p>\u9664\u4ee5\u4e0a\u5217\u51fa\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5916\uff0c\u8fd8\u6709\u6307\u9488\uff08pointer\uff09\u548cvoid \u53c2\u6570\u8868\u793a\u7c7b\u578b\uff0c\u6211\u4eec\u5c06\u5728\u540e\u9762\u770b\u5230\u3002<\/p>\n\n\n\n<h3>\u53d8\u91cf\u7684\u58f0\u660e\uff08Declaration of variables\uff09<\/h3>\n\n\n\n<p>\u5728C++\u4e2d\u8981\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf\u5fc5\u987b\u5148\u58f0\u660e\uff08declare\uff09\u8be5\u53d8\u91cf\u7684\u6570\u636e\u7c7b\u578b\u3002\u58f0\u660e\u4e00\u4e2a\u65b0\u53d8\u91cf\u7684\u8bed\u6cd5\u662f\u5199\u51fa\u6570\u636e\u7c7b\u578b\u6807\u8bc6\u7b26\uff08\u4f8b\u5982int, short, float&#8230;) \u540e\u9762\u8ddf\u4e00\u4e2a\u6709\u6548\u7684\u53d8\u91cf\u6807\u8bc6\u540d\u79f0\u3002\u4f8b\u5982\uff1aint a;<br>float mynumber;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4e24\u4e2a\u5747\u4e3a\u6709\u6548\u7684\u53d8\u91cf\u58f0\u660e\uff08variable declaration\uff09\u3002\u7b2c\u4e00\u4e2a\u58f0\u660e\u4e00\u4e2a\u6807\u8bc6\u4e3aa \u7684\u6574\u578b\u53d8\u91cf(int variable)\uff0c\u7b2c\u4e8c\u4e2a\u58f0\u660e\u4e00\u4e2a\u6807\u8bc6\u4e3amynumber \u7684\u6d6e\u70b9\u578b\u53d8\u91cf(float variable)\u3002\u58f0\u660e\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u540e\u9762\u7684\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u53d8\u91cfa\u548c mynumber \u4e86\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u9700\u8981\u58f0\u660e\u591a\u4e2a\u540c\u4e00\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u4f60\u53ef\u4ee5\u5c06\u5b83\u4eec\u7f29\u5199\u5728\u540c\u4e00\u884c\u58f0\u660e\u4e2d\uff0c\u5728\u6807\u8bc6\u4e4b\u95f4\u7528\u9017\u53f7(comma) \u5206\u9694\u3002\u4f8b\u5982\uff1aint a, b, c;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u8bed\u53e5\u540c\u65f6\u5b9a\u4e49\u4e86a\u3001b\u3001c 3\u4e2a\u6574\u578b\u53d8\u91cf\uff0c\u5b83\u4e0e\u4e0b\u9762\u7684\u5199\u6cd5\u5b8c\u5168\u7b49\u540c\uff1aint a;<br>int b;<br>int c;<\/p>\n\n\n\n<p>\u6574\u578b\u6570\u636e\u7c7b\u578b (char, short, long \u548c int) \u53ef\u4ee5\u662f\u6709\u7b26\u53f7\u7684\uff08signed\uff09\u6216\u65e0\u7b26\u53f7\u7684\uff08unsigned \uff09\uff0c\u8fd9\u53d6\u51b3\u4e8e\u6211\u4eec\u9700\u8981\u8868\u793a\u7684\u6570\u636e\u8303\u56f4\u3002\u6709\u7b26\u53f7\u7c7b\u578b(signed)\u53ef\u4ee5\u8868\u793a\u6b63\u6570\u548c\u8d1f\u6570\uff0c\u800c\u65e0\u7b26\u53f7\u7c7b\u578b(unsigned)\u53ea\u80fd\u8868\u793a\u6b63\u6570\u548c0\u3002\u5728\u5b9a\u4e49\u4e00\u4e2a\u6574\u578b\u6570\u636e\u53d8\u91cf\u65f6\u53ef\u4ee5\u5728\u6570\u636e\u7c7b\u578b\u524d\u9762\u52a0\u5173\u952e\u5b57 signed \u6216 unsigned \u6765\u58f0\u660e\u6570\u636e\u7684\u7b26\u53f7\u7c7b\u578b\u3002\u4f8b\u5982\uff1aunsigned short NumberOfSons;<br>signed int MyAccountBalance;<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u6ca1\u6709\u7279\u522b\u5199\u51fasigned\u6216 unsigned\uff0c\u53d8\u91cf\u9ed8\u8ba4\u4e3asigned\uff0c\u56e0\u6b64\u4ee5\u4e0a\u7b2c\u4e8c\u4e2a\u58f0\u660e\u6211\u4eec\u4e5f\u53ef\u4ee5\u5199\u6210\uff1aint MyAccountBalance;<\/p>\n\n\n\n<p>\u56e0\u4e3a\u4ee5\u4e0a\u4e24\u79cd\u8868\u793a\u65b9\u5f0f\u610f\u4e49\u5b8c\u5168\u4e00\u6837\uff0c\u56e0\u6b64\u6211\u4eec\u5728\u6e90\u7a0b\u5e8f\u901a\u5e38\u7701\u7565\u5173\u952e\u5b57signed \u3002<\/p>\n\n\n\n<p>\u552f\u4e00\u7684\u4f8b\u5916\u662f\u5b57\u7b26\u578b\uff08char\uff09\u53d8\u91cf\uff0c\u8fd9\u79cd\u53d8\u91cf\u72ec\u7acb\u5b58\u5728\uff0c\u4e0esigned char \u548c unsigned char\u578b\u5747\u4e0d\u76f8\u540c\u3002<\/p>\n\n\n\n<p>short \u548c long \u53ef\u4ee5\u88ab\u5355\u72ec\u7528\u6765\u8868\u793a\u6574\u578b\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0cshort \u76f8\u5f53\u4e8e short int\uff0c long \u76f8\u5f53\u4e8e long int\u3002\u4e5f\u5c31\u662f\u8bf4 short year; \u548c short int year; \u4e24\u79cd\u58f0\u660e\u662f\u7b49\u4ef7\u7684\u3002<\/p>\n\n\n\n<p>\u6700\u540e\uff0csigned \u548c unsigned \u4e5f\u53ef\u4ee5\u88ab\u5355\u72ec\u7528\u6765\u8868\u793a\u7b80\u5355\u7c7b\u578b\uff0c\u610f\u601d\u5206\u522b\u540csigned int \u548c unsigned int \u76f8\u540c\uff0c\u5373\u4ee5\u4e0b\u4e24\u79cd\u58f0\u660e\u4e92\u76f8\u7b49\u540c\uff1aunsigned MyBirthYear;<br>unsigned int MyBirthYear;<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u5c31\u7528C++\u4ee3\u7801\u6765\u89e3\u51b3\u5728\u8fd9\u4e00\u8282\u5f00\u5934\u63d0\u5230\u7684\u8bb0\u5fc6\u95ee\u9898\uff0c\u6765\u770b\u4e00\u4e0b\u53d8\u91cf\u5b9a\u4e49\u662f\u5982\u4f55\u5728\u7a0b\u5e8f\u4e2d\u8d77\u4f5c\u7528\u7684\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ operating with variables<br><br>#include &lt;iostream.h&gt;<br>using namespace std;<br><br>int main ()<br>{<br>&nbsp;&nbsp;&nbsp; \/\/ declaring variables:<br>&nbsp;&nbsp;&nbsp; int a, b;<br>&nbsp;&nbsp;&nbsp; int result;<br><br>&nbsp;&nbsp;&nbsp; \/\/ process:<br>&nbsp;&nbsp;&nbsp; a = 5;<br>&nbsp;&nbsp;&nbsp; b = 2;<br>&nbsp;&nbsp;&nbsp; a = a + 1;<br>&nbsp;&nbsp;&nbsp; result = a &#8211; b;<br><br>&nbsp;&nbsp;&nbsp; \/\/ print out the result:<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; result;<br><br>&nbsp;&nbsp;&nbsp; \/\/ terminate the program:<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5982\u679c\u4ee5\u4e0a\u7a0b\u5e8f\u4e2d\u53d8\u91cf\u58f0\u660e\u90e8\u5206\u6709\u4f60\u4e0d\u719f\u6089\u7684\u5730\u65b9\uff0c\u4e0d\u7528\u62c5\u5fc3\uff0c\u6211\u4eec\u5728\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u5f88\u5feb\u4f1a\u5b66\u5230\u8fd9\u4e9b\u5185\u5bb9\u3002<\/p>\n\n\n\n<h3>\u53d8\u91cf\u7684\u8303\u56f4\uff08Scope of variables\uff09<\/h3>\n\n\n\n<p><img loading=\"lazy\" height=\"45\" width=\"71\" src=\"http:\/\/www.prglab.com\/cms\/media\/images\/cplusplus\/c-diff.jpg\">\u6240\u6709\u6211\u4eec\u8981\u4f7f\u7528\u7684\u53d8\u91cf\u90fd\u5fc5\u987b\u4e8b\u5148\u58f0\u660e\u8fc7\u3002\uff23\u548c\uff23++\u8bed\u8a00\u7684\u4e00\u4e2a\u91cd\u8981\u533a\u522b\u662f\uff0c\u5728C++\u8bed\u8a00\u4e2d\u6211\u4eec\u53ef\u4ee5\u5728\u6e90\u7a0b\u5e8f\u4e2d\u4efb\u4f55\u5730\u65b9\u58f0\u660e\u53d8\u91cf\uff0c\u751a\u81f3\u53ef\u4ee5\u5728\u4e24\u4e2a\u53ef\u6267\u884c(excutable)\u8bed\u53e5\u7684\u4e2d\u95f4\u58f0\u660e\u53d8\u91cf\uff0c\u800c\u4e0d\u8c61\u5728C\u8bed\u8a00\u4e2d\u53d8\u91cf\u58f0\u660e\u53ea\u80fd\u5728\u7a0b\u5e8f\u7684\u5f00\u5934\u90e8\u5206\u3002<\/p>\n\n\n\n<p>\u7136\u800c\uff0c\u6211\u4eec\u8fd8\u662f\u5efa\u8bae\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u9075\u5faaC\u8bed\u8a00\u7684\u4e60\u60ef\u6765\u58f0\u660e\u53d8\u91cf\uff0c\u56e0\u4e3a\u5c06\u53d8\u91cf\u58f0\u660e\u653e\u5728\u4e00\u5904\u5bf9debug\u7a0b\u5e8f\u6709\u597d\u5904\u3002\u56e0\u6b64\uff0c\u4f20\u7edf\u7684C\u8bed\u8a00\u65b9\u5f0f\u7684\u53d8\u91cf\u58f0\u660e\u5c31\u662f\u628a\u53d8\u91cf\u58f0\u660e\u653e\u5728\u6bcf\u4e00\u4e2a\u51fd\u6570(function)\u7684\u5f00\u5934\uff08\u5bf9\u672c\u5730\u53d8\u91cflocal variable\uff09\u6216\u76f4\u63a5\u653e\u5728\u7a0b\u5e8f\u5f00\u5934\u6240\u6709\u51fd\u6570(function)\u7684\u5916\u9762\uff08\u5bf9\u5168\u5c40\u53d8\u91cfglobal variable\uff09\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2a\u53d8\u91cf\u53ef\u4ee5\u662f\u672c\u5730(local)\u8303\u56f4\u5185\u6709\u6548\uff0c\u53eb\u505a\u672c\u5730\u53d8\u91cf\uff0c\u4e5f\u53ef\u4ee5\u662f\u5168\u5c40(global)\u8303\u56f4\u5185\u6709\u6548\uff0c\u53eb\u505a\u5168\u5c40\u53d8\u91cf\u3002\u5168\u5c40\u53d8\u91cf\u8981\u5b9a\u4e49\u5728\u4e00\u4e2a\u6e90\u7801\u6587\u4ef6\u7684\u4e3b\u4f53\u4e2d\uff0c\u6240\u6709\u51fd\u6570(\u5305\u62ec\u4e3b\u51fd\u6570main()\uff09\u4e4b\u5916\u3002\u800c\u672c\u5730\u53d8\u91cf\u5b9a\u4e49\u5728\u4e00\u4e2a\u51fd\u6570\u751a\u81f3\u53ea\u662f\u4e00\u4e2a\u8bed\u53e5\u5757\u5355\u5143\u4e2d\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><img loading=\"lazy\" height=\"290\" width=\"417\" src=\"http:\/\/www.prglab.com\/cms\/media\/images\/cplusplus\/img1-2-1.gif\"><strong>\u5168\u5c40\u53d8\u91cfGlobal variables<\/strong>&nbsp;\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u4efb\u4f55\u5730\u65b9\u4efb\u4f55\u51fd\u6570\uff08function\uff09\u4e2d\u88ab\u5f15\u7528\uff0c\u53ea\u8981\u662f\u5728\u53d8\u91cf\u7684\u58f0\u660e\u4e4b\u540e\u3002<strong>\u672c\u5730\u53d8\u91cflocal variables<\/strong>&nbsp;\u7684\u4f5c\u7528\u8303\u56f4\u88ab\u5c40\u9650\u5728\u58f0\u660e\u5b83\u7684\u7a0b\u5e8f\u8303\u56f4\u5185\u3002\u5982\u679c\u5b83\u4eec\u662f\u5728\u4e00\u4e2a\u51fd\u6570\u7684\u5f00\u5934\u88ab\u58f0\u660e\u7684\uff08\u4f8b\u5982main\u51fd\u6570\uff09\uff0c\u5b83\u4eec\u7684\u4f5c\u7528\u8303\u56f4\u5c31\u662f\u6574\u4e2amain\u51fd\u6570\u3002\u5728\u5de6\u56fe\u7684\u4f8b\u5b50\u4e2d\uff0c\u8fd9\u5c31\u610f\u5473\u7740\u5982\u679c\u5728main\u51fd\u6570\u5916\u8fd8\u53e6\u6709\u4e00\u4e2a\u51fd\u6570\uff0cmain\u51fd\u6570\u4e2d\u58f0\u660e\u7684\u672c\u5730\u53d8\u91cf(Age, ANumber, AnotherOne) \u4e0d\u80fd\u591f\u88ab\u53e6\u4e00\u4e2a\u51fd\u6570\u4f7f\u7528\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u5728C++\u4e2d\uff0c\u672c\u5730\u53d8\u91cf(local variable)\u7684\u4f5c\u7528\u8303\u56f4\u88ab\u5b9a\u4e49\u5728\u58f0\u660e\u5b83\u7684\u7a0b\u5e8f\u5757\u5185\uff08\u4e00\u4e2a\u7a0b\u5e8f\u5757\u662f\u88ab\u4e00\u5bf9\u82b1\u62ec\u53f7\uff08curly brackets{}\uff09\u62ec\u8d77\u6765\u7684\u4e00\u7ec4\u8bed\u53e5\uff09\u3002\u5982\u679c\u53d8\u91cf\u662f\u5728\u4e00\u4e2a\u51fd\u6570(function)\u4e2d\u88ab\u58f0\u660e\u7684\uff0c\u90a3\u4e48\u5b83\u662f\u4e00\u4e2a\u51fd\u6570\u8303\u56f4\u5185\u7684\u53d8\u91cf\uff0c\u5982\u679c\u53d8\u91cf\u662f\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d(loop)\u4e2d\u88ab\u58f0\u660e\u7684\uff0c\u90a3\u4e48\u5b83\u7684\u4f5c\u7528\u8303\u56f4\u53ea\u662f\u5728\u8fd9\u4e2a\u5faa\u73af(loop)\u4e4b\u4e2d\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u9664\u672c\u5730\u548c\u5168\u5c40\u8303\u56f4\u5916\uff0c\u8fd8\u6709\u4e00\u79cd\u5916\u90e8\u8303\u56f4\uff0c\u5b83\u4f7f\u5f97\u4e00\u4e2a\u53d8\u91cf\u4e0d\u4ec5\u5728\u540c\u4e00\u6e90\u7a0b\u5e8f\u6587\u4ef6\u4e2d\u53ef\u89c1\uff0c\u800c\u4e14\u5728\u5176\u4ed6\u6240\u6709\u5c06\u88ab\u94fe\u63a5\u5728\u4e00\u8d77\u7684\u6e90\u6587\u4ef6\u4e2d\u5747\u53ef\u89c1\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3>\u53d8\u91cf\u521d\u59cb\u5316\uff08Initialization of variables\uff09<\/h3>\n\n\n\n<p>\u5f53\u4e00\u4e2a\u672c\u5730\u53d8\u91cf( local variable)\u88ab\u58f0\u660e\u65f6\uff0c\u5b83\u7684\u503c\u9ed8\u8ba4\u4e3a\u672a\u5b9a(undetermined)\u3002\u4f46\u4f60\u53ef\u80fd\u5e0c\u671b\u5728\u58f0\u660e\u53d8\u91cf\u7684\u540c\u65f6\u8d4b\u7ed9\u5b83\u4e00\u4e2a\u5177\u4f53\u7684\u503c\u3002\u8981\u60f3\u8fbe\u5230\u8fd9\u4e2a\u76ee\u7684\uff0c\u9700\u8981\u5bf9\u53d8\u91cf\u8fdb\u884c\u521d\u59cb\u5316\u3002C++\u4e2d\u6709\u4e24\u79cd\u521d\u59cb\u5316\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p>\u7b2c\u4e00\u79cd\uff0c\u53c8\u53eb\u505a\u7c7bC (c-like) \u65b9\u6cd5\uff0c\u662f\u5728\u58f0\u660e\u53d8\u91cf\u7684\u65f6\u5019\u52a0\u4e0a\u4e00\u4e2a\u7b49\u4e8e\u53f7\uff0c\u5e76\u5728\u540e\u9762\u8ddf\u4e0a\u60f3\u8981\u7684\u6570\u503c\uff1atype identifier = initial_value ;<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u60f3\u58f0\u660e\u4e00\u4e2a\u53eb\u505aa\u7684int\u53d8\u91cf\u5e76\u540c\u65f6\u8d4b\u4e88\u5b830\u8fd9\u4e2a\u503c\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u5199\uff1aint a = 0;<\/p>\n\n\n\n<p>\u53e6\u5916\u4e00\u79cd\u53d8\u91cf\u521d\u59cb\u5316\u7684\u65b9\u6cd5\uff0c\u53c8\u53eb\u505a\u6784\u9020\u51fd\u6570(constructor)\u521d\u59cb\u5316\uff0c \u662f\u5c06\u521d\u59cb\u503c\u7528\u5c0f\u62ec\u53f7\uff08parenthesis ()\uff09\u62ec\u8d77\u6765:type identifier (initial_value) ;<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1aint a (0);<\/p>\n\n\n\n<p>\u5728C++.\u4e2d\u4ee5\u4e0a\u4e24\u79cd\u65b9\u6cd5\u90fd\u6b63\u786e\u5e76\u4e14\u4e24\u8005\u7b49\u540c \u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ \u53d8\u91cf\u521d\u59cb\u5316<br><br>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main ()<br>{<br>int a=5; \/\/ \u521d\u59cb\u503c\u4e3a 5<br>int b(2); \/\/ \u521d\u59cb\u503c\u4e3a 2<br>int result; \/\/ \u4e0d\u786e\u5b9a\u521d\u59cb\u503c<br><br>a = a + 3;<br>result = a &#8211; b;<br>cout &lt;&lt; result;<br><br>return 0;<br>}<br><\/td><td>6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3><strong>\u5b57\u7b26\u4e32 \uff08strings)<\/strong><\/h3>\n\n\n\n<p>\u5b57\u7b26\u4e32\u662f\u7528\u6765\u5b58\u50a8\u4e00\u4e2a\u4ee5\u4e0a\u5b57\u7b26\u7684\u975e\u6570\u5b57\u503c\u7684\u53d8\u91cf\u3002<\/p>\n\n\n\n<p>C++\u63d0\u4f9b\u4e00\u4e2astring\u7c7b\u6765\u652f\u6301\u5b57\u7b26\u4e32\u7684\u64cd\u4f5c\uff0c\u5b83\u4e0d\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f46\u662f\u5728\u4e00\u822c\u7684\u4f7f\u7528\u4e2d\u4e0e\u57fa\u672c\u6570\u636e\u7c7b\u578b\u975e\u5e38\u76f8\u4f3c\u3002<\/p>\n\n\n\n<p>\u4e0e\u666e\u901a\u6570\u636e\u7c7b\u578b\u4e0d\u540c\u7684\u4e00\u70b9\u662f\uff0c\u8981\u60f3\u58f0\u660e\u548c\u4f7f\u7528\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u9700\u8981\u5f15\u7528\u5934\u6587\u4ef6&lt;string&gt;\uff0c\u5e76\u4e14\u4f7f\u7528using namespace\u8bed\u53e5\u6765\u4f7f\u7528\u6807\u51c6\u540d\u7a7a\u95f4\uff08std)\uff0c\u5982\u4e0b\u9762\u4f8b\u5b50\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ C++\u5b57\u7b26\u4e32\u4f8b\u9898<br>#include &lt;iostream&gt;<br>#include &lt;string&gt;<br>using&nbsp;namespace std;<br><br>int main ()<br>{<br>string mystring = &#8220;This is a string&#8221;;<br>cout &lt;&lt; mystring;<br>return 0;<br>}<\/td><td>This is a string<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5982\u4e0a\u9762\u4f8b\u5b50\u6240\u793a\uff0c\u5b57\u7b26\u4e32\u53d8\u91cf\u53ef\u4ee5\u88ab\u521d\u59cb\u5316\u4e3a\u4efb\u4f55\u5b57\u7b26\u4e32\u503c\uff0c\u5c31\u50cf\u6570\u5b57\u7c7b\u578b\u53d8\u91cf\u53ef\u4ee5\u88ab\u521d\u59cb\u5316\u4e3a\u4efb\u4f55\u6570\u5b57\u503c\u4e00\u6837\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u4e24\u79cd\u521d\u59cb\u5316\u683c\u5f0f\u5bf9\u5b57\u7b26\u4e32\u53d8\u91cf\u90fd\u662f\u53ef\u4ee5\u4f7f\u7528\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string mystring = \"This is a string\";<br>string mystring (\"This is a string\");<\/pre>\n\n\n\n<p>\u5b57\u7b26\u4e32\u53d8\u91cf\u8fd8\u53ef\u4ee5\u8fdb\u884c\u5176\u4ed6\u4e0e\u57fa\u672c\u6570\u636e\u7c7b\u578b\u53d8\u91cf\u4e00\u6837\u7684\u64cd\u4f5c\uff0c\u6bd4\u5982\u58f0\u660e\u7684\u65f6\u5019\u4e0d\u6307\u5b9a\u521d\u59cb\u503c\uff0c\u548c\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u88ab\u91cd\u65b0\u8d4b\u503c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\/\/ C++\u5b57\u7b26\u4e32\u4f8b\u98982<br>&nbsp;#include &lt;iostream&gt;<br>#include &lt;string&gt;<br>using namespace std;<br><br>int main ()<br>{<br>string mystring;<br>mystring =<br>&#8220;This is the initial string content&#8221;;<br>cout &lt;&lt; mystring &lt;&lt; endl;<br>mystring =<br>&#8220;This is a different string content&#8221;;<br>cout &lt;&lt; mystring &lt;&lt; endl;<br>return 0;<br>}<\/td><td>This is the initial string content<br>This is a different string content<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8981\u4e86\u89e3\u66f4\u52a0\u8be6\u7ec6\u7684C++\u5b57\u7b26\u4e32\u64cd\u4f5c\uff0c\u5efa\u8bae\u53c2\u8003Cplusplus\u4e0a\u7684<a target=\"_blank\" href=\"http:\/\/www.cplusplus.com\/reference\/string\/string\/\" rel=\"noreferrer noopener\">string\u7c7breference<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.2 \u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b \uff08Variables and Data types \uff09 \u4f60\u53ef\u80fd\u89c9\u5f97\u8fd9\u4e2a\u201cHellow World\u201d\u7a0b\u5e8f\u7528\u5904\u4e0d\u5927\u3002\u6211\u4eec\u5199\u4e86\u597d\u51e0\u884c\u4ee3\u7801\uff0c\u7f16\u8bd1\uff0c\u7136\u540e\u6267\u884c\u751f\u6210\u7684\u7a0b\u5e8f\u53ea\u662f\u4e3a\u4e86\u5728\u5c4f\u5e55\u4e0a\u770b\u5230\u4e00\u53e5\u8bdd\u3002\u7684\u786e\uff0c\u6211\u4eec\u76f4\u63a5\u5728\u5c4f\u5e55\u4e0a\u6253\u51fa\u8fd9\u53e5\u8bdd\u4f1a\u66f4\u5feb\u3002\u4f46\u662f\u7f16\u7a0b\u5e76\u4e0d\u4ec5\u9650\u4e8e\u5728\u5c4f\u5e55\u4e0a\u6253\u51fa\u6587\u5b57\u8fd9\u4e48\u7b80\u5355\u7684\u5de5\u4f5c\u3002\u4e3a\u4e86\u80fd\u591f\u8fdb\u4e00\u6b65\u5199\u51fa\u53ef\u4ee5\u6267\u884c\u66f4\u6709\u7528\u7684\u4efb\u52a1\u7684\u7a0b\u5e8f\uff0c\u6211\u4eec\u9700\u8981\u5f15\u5165\u53d8\u91cf\uff08variable\uff09\u8fd9\u4e2a\u7684\u6982\u5ff5\u3002 \u8ba9\u6211\u4eec\u8bbe\u60f3\u8fd9\u6837\u4e00\u4e2a\u4f8b\u5b50\uff0c\u6211\u8981\u6c42\u4f60\u5728\u8111\u5b50\u91cc\u8bb0\u4f4f5\u8fd9\u4e2a\u6570\u5b57\uff0c\u7136\u540e\u518d\u8bb0\u4f4f2\u8fd9\u4e2a\u6570\u5b57\u3002\u4f60\u5df2\u7ecf\u5b58\u50a8\u4e86\u4e24\u4e2a\u6570\u503c\u5728\u4f60\u7684\u8bb0\u5fc6\u91cc\u3002\u73b0\u5728\u6211\u8981\u6c42\u4f60\u5728\u6211\u8bf4\u7684\u7b2c\u4e00\u4e2a\u6570\u503c\u4e0a\u52a01\uff0c\u4f60\u5e94\u8be5\u4fdd\u75596 \uff08\u53735+1\uff09\u548c2\u5728\u4f60\u7684\u8bb0\u5fc6\u91cc\u3002\u73b0\u5728\u5982\u679c\u6211\u4eec\u5c06\u4e24\u6570\u76f8\u51cf\u53ef\u4ee5\u5f97\u5230\u7ed3\u679c4\u3002 \u6240\u6709\u8fd9\u4e9b\u4f60\u5728\u8111\u5b50\u91cc\u505a\u7684\u4e8b\u60c5\u4e0e\u8ba1\u7b97\u673a\u7528\u4e24\u4e2a\u53d8\u91cf\u53ef\u4ee5\u505a\u7684\u4e8b\u60c5\u975e\u5e38\u76f8\u4f3c\u3002\u540c\u6837\u7684\u5904\u7406\u8fc7\u7a0b\u7528C++\u6765\u8868\u793a\u53ef\u4ee5\u5199\u6210\u4e0b\u9762\u4e00\u6bb5\u4ee3\u7801\uff1aa = 5;b = 2;a = a + 1;result = a &#8211; b; \u5f88\u660e\u663e\u8fd9\u662f\u4e00\u4e2a\u5f88\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u7528\u4e86\u4e24\u4e2a\u5c0f\u7684\u6574\u6570\u6570\u503c\u3002\u4f46\u662f\u60f3\u4e00\u60f3\u4f60\u7684\u7535\u8111\u53ef\u4ee5\u540c\u65f6\u5b58\u50a8\u6210\u5343\u4e0a\u4e07\u8fd9\u6837\u7684\u6570\u503c\uff0c\u5e76\u8fdb\u884c\u590d\u6742\u7684\u6570\u5b66\u8fd0\u7b97\u3002 \u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u53d8\u91cf\uff08variable\uff09\u5b9a\u4e49\u4e3a\u5185\u5b58\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4ee5\u5b58\u50a8\u4e00\u4e2a\u786e\u5b9a\u7684\u503c\u3002 \u6bcf\u4e00\u4e2a\u53d8\u91cf (variable)\u9700\u8981\u4e00\u4e2a\u6807\u8bc6\uff0c\u4ee5\u4fbf\u5c06\u5b83\u4e0e\u5176\u4ed6\u53d8\u91cf\u76f8\u533a\u522b\uff0c\u4f8b\u5982\uff0c\u5728\u524d\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u53d8\u91cf\u6807\u8bc6\u662fa, b,&nbsp;\u548cresult\u3002\u6211\u4eec\u53ef\u4ee5\u7ed9\u53d8\u91cf\u8d77\u4efb\u4f55\u540d\u5b57\uff0c\u53ea\u8981\u5b83\u4eec\u662f\u6709\u6548\u7684\u6807\u8bc6\u7b26\u3002 \u6807\u8bc6\uff08Identifiers\uff09 \u6709\u6548\u6807\u8bc6\u7531\u5b57\u6bcd(letter)\uff0c\u6570\u5b57(digits)\u548c\u4e0b\u5212\u7ebf ( _ )\u7ec4\u6210\u3002\u6807\u8bc6\u7684\u957f\u5ea6\u6ca1\u6709\u9650\u5236\uff0c\u4f46\u662f\u6709\u4e9b\u7f16\u8bd1\u5668\u53ea\u53d6\u524d32\u4e2a\u5b57\u7b26\uff08\u5269\u4e0b\u7684\u5b57\u7b26\u4f1a\u88ab\u5ffd\u7565\uff09\u3002 \u7a7a\u683c(spaces)\uff0c\u6807\u70b9(punctuation marks)\u548c\u7b26\u53f7(symbols) \u90fd\u4e0d\u53ef\u4ee5\u51fa\u73b0\u5728\u6807\u8bc6\u4e2d\u3002 \u53ea\u6709\u5b57\u6bcd(letters)\uff0c\u6570\u5b57(digits) \u548c\u4e0b\u5212\u7ebf(_)\u662f\u5408\u6cd5\u7684\u3002\u5e76\u4e14\u53d8\u91cf\u6807\u8bc6\u5fc5\u987b\u4ee5\u5b57\u6bcd\u5f00\u5934\u3002\u6807\u8bc6\u4e5f\u53ef\u80fd\u4ee5\u4e0b\u5212\u7ebf\uff08_\uff09\u5f00\u5934\uff0c\u4f46\u8fd9\u79cd\u6807\u8bc6\u901a\u5e38\u662f\u4fdd\u7559\u7ed9\u4e3a\u5916\u90e8\u8fde\u63a5\u7528\u7684\u3002\u6807\u8bc6\u4e0d\u53ef\u4ee5\u4ee5\u6570\u5b57\u5f00\u5934\u3002 \u5fc5\u987b\u6ce8\u610f\u7684\u53e6\u4e00\u6761\u89c4\u5219\u662f\u5f53\u4f60\u7ed9\u53d8\u91cf\u8d77\u540d\u5b57\u65f6\u4e0d\u53ef\u4ee5\u548cC++\u8bed\u8a00\u7684\u5173\u952e\u5b57\u6216\u4f60\u6240\u4f7f\u7528\u7684\u7f16\u8bd1\u5668\u7684\u7279\u6b8a\u5173\u952e\u5b57\u540c\u540d\uff0c\u56e0\u4e3a\u8fd9\u6837\u4e0e\u8fd9\u4e9b\u5173\u952e\u5b57\u4ea7\u751f\u6df7\u6dc6\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u5217\u51fa\u6807\u51c6\u4fdd\u7559\u5173\u952e\u5b57\uff0c\u4ed6\u4eec\u4e0d\u5141\u8bb8\u88ab\u7528\u4f5c\u53d8\u91cf\u6807\u8bc6\u540d\u79f0\uff1a asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":309,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/313"}],"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=313"}],"version-history":[{"count":1,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/313\/revisions"}],"predecessor-version":[{"id":314,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/pages\/313\/revisions\/314"}],"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=313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}