{"id":10021129,"date":"2025-12-18T23:37:18","date_gmt":"2025-12-18T15:37:18","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021129"},"modified":"2025-12-18T23:37:18","modified_gmt":"2025-12-18T15:37:18","slug":"%e3%80%8ac%e8%af%ad%e8%a8%80%e7%94%b5%e5%ad%90%e4%b9%a6-2026%e6%9c%80%e6%96%b0%e7%89%88%e3%80%8b-c%e8%af%ad%e8%a8%80%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e6%a6%82%e8%bf%b0","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021129","title":{"rendered":"\u300aC\u8bed\u8a00\u7535\u5b50\u4e66-2026\u6700\u65b0\u7248\u300b-C\u8bed\u8a00\u6570\u636e\u7c7b\u578b\u6982\u8ff0"},"content":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u826f\u8bb8\uff0c\u4e00\u4e2a\u6df1\u8015\u5d4c\u5165\u5f0f 12 \u5e74\u7684\u8001\u5de5\u7a0b\u5e08\uff0c\u524d\u4e16\u754c 500 \u5f3a\u9ad8\u5de5\u3002<\/p>\n<p>\u6211\u82b1\u4e86 3 \u4e2a\u6708\u65f6\u95f4\uff0c\u5199\u4e86\u4e00\u4e2a <a href=\"https:\/\/link.segmentfault.com\/?enc=Lvdv1T75heePgnj%2BO7NVdg%3D%3D.ZhaqAQMmQcN2WEMV4lyS%2FBdbPpVKCAxX%2BHthRbgL78CWXmlvXbgtUmsqRZByROUSw9AdJ%2Bnfq6DDjfuUabRPNw%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">C \u8bed\u8a00\u7535\u5b50\u4e66<\/a>\uff0c\u4ee5\u975e\u5e38\u901a\u4fd7\u7684\u8bed\u8a00\u8ddf\u5927\u5bb6\u8bb2\u89e3 C \u8bed\u8a00\uff0c\u628a\u590d\u6742\u7684\u6280\u672f\u8bb2\u5f97\u8fde\u5c0f\u5b66\u751f\u90fd\u80fd\u542c\u5f97\u61c2\uff0c\u7edd\u4e0d\u662f AI \u751f\u6210\u90a3\u79cd\u6666\u6da9\u96be\u61c2\u7684\u7535\u5b50\u5783\u573e\u3002<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=hXwYZ%2F5b7L2iShg2ywr41w%3D%3D.aGmuF3J4xV%2BCTWrVtHd5NQbsIjGqTlomBOyheQJYMKJmVnNMhzenxFjvXo4P6m9U%2BGED6t6W9mjskmxlj2LCrg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u70b9\u51fb\u6b64\u5904\u514d\u8d39\u9886\u53d6 C \u8bed\u8a00\u7535\u5b50\u4e66<\/a><\/p>\n<p>C \u8bed\u8a00\u7535\u5b50\u4e66\u76ee\u5f55\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000047485229\" alt=\"\" title=\"\"><\/p>\n<h3>2.1 C\u8bed\u8a00\u6570\u636e\u7c7b\u578b\u6982\u8ff0<\/h3>\n<p>\u5728\u6211\u4eec\u7684\u65e5\u5e38\u751f\u6d3b\u4e2d\uff0c\u6211\u4eec\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u4fe1\u606f\uff1a\u6570\u5b57\u3001\u6587\u5b57\u3001\u56fe\u7247\u3001\u58f0\u97f3\u7b49\u7b49\u3002\u6bd4\u5982\u4f60\u7684\u5e74\u9f84\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u4f60\u7684\u59d3\u540d\u662f\u4e00\u6bb5\u6587\u5b57\uff0c\u4f60\u7684\u7167\u7247\u662f\u56fe\u50cf\u4fe1\u606f\u3002\u4e0d\u540c\u7c7b\u578b\u7684\u4fe1\u606f\u9700\u8981\u7528\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u5904\u7406\u548c\u5b58\u50a8\u3002<\/p>\n<p>\u540c\u6837\u5730\uff0c\u5728\u8ba1\u7b97\u673a\u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u4e5f\u9700\u8981\u5904\u7406\u5404\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5b58\u50a8\u4e00\u4e2a\u4eba\u7684\u5e74\u9f84\uff0c\u6709\u65f6\u5019\u9700\u8981\u5b58\u50a8\u4e00\u4e2a\u4eba\u7684\u8eab\u9ad8\uff0c\u6709\u65f6\u5019\u9700\u8981\u5b58\u50a8\u4e00\u4e2a\u4eba\u7684\u59d3\u540d\u3002\u8fd9\u4e9b\u4e0d\u540c\u79cd\u7c7b\u7684\u6570\u636e\u5c31\u9700\u8981\u7528\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u6765\u8868\u793a\u3002<\/p>\n<p>\u6570\u636e\u7c7b\u578b\u5c31\u50cf\u662f\u7ed9\u6570\u636e\u8d34\u4e0a\u7684&#8221;\u6807\u7b7e&#8221;\uff0c\u544a\u8bc9\u8ba1\u7b97\u673a\u8fd9\u4e2a\u6570\u636e\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\uff0c\u5e94\u8be5\u5982\u4f55\u5904\u7406\u3002\u5c31\u50cf\u8d85\u5e02\u91cc\u7684\u5546\u54c1\u90fd\u6709\u6807\u7b7e\u4e00\u6837\uff0c\u98df\u54c1\u7c7b\u5546\u54c1\u6709\u98df\u54c1\u6807\u7b7e\uff0c\u7535\u5b50\u4ea7\u54c1\u6709\u7535\u5b50\u4ea7\u54c1\u6807\u7b7e\uff0c\u4e0d\u540c\u7684\u6807\u7b7e\u51b3\u5b9a\u4e86\u5546\u54c1\u7684\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n<h4>2.1.1 \u6570\u636e\u7c7b\u578b\u5206\u7c7b<\/h4>\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u5927\u5bb6\u65cf\uff0c\u8fd9\u4e2a\u5bb6\u65cf\u6709\u5f88\u591a\u5206\u652f\u3002\u8ba9\u6211\u4eec\u7528\u4e00\u4e2a\u5bb6\u65cf\u65cf\u8c31\u7684\u65b9\u5f0f\u6765\u7406\u89e3C\u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b\u5206\u7c7b\u3002<\/p>\n<p>\u6574\u4e2aC\u8bed\u8a00\u6570\u636e\u7c7b\u578b\u5bb6\u65cf\u53ef\u4ee5\u5206\u4e3a\u4e24\u5927\u4e3b\u8981\u5206\u652f\uff1a<strong>\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/strong>\u548c<strong>\u6784\u9020\u6570\u636e\u7c7b\u578b<\/strong>\u3002\u8fd9\u5c31\u50cf\u4e00\u4e2a\u5927\u5bb6\u65cf\u5206\u4e3a&#8221;\u539f\u751f\u5bb6\u5ead\u6210\u5458&#8221;\u548c&#8221;\u901a\u8fc7\u7ed3\u5408\u7ec4\u6210\u7684\u65b0\u5bb6\u5ead&#8221;\u4e00\u6837\u3002<\/p>\n<p><strong>1. \u57fa\u672c\u6570\u636e\u7c7b\u578b\u8be6\u89e3<\/strong><\/p>\n<p>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u662fC\u8bed\u8a00\u4e2d\u6700\u57fa\u7840\u3001\u6700\u539f\u59cb\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5c31\u50cf\u5316\u5b66\u4e2d\u7684\u539f\u5b50\u4e00\u6837\uff0c\u5b83\u4eec\u662f\u6784\u6210\u5176\u4ed6\u590d\u6742\u6570\u636e\u7c7b\u578b\u7684\u57fa\u7840\u3002\u57fa\u672c\u6570\u636e\u7c7b\u578b\u53c8\u53ef\u4ee5\u7ec6\u5206\u4e3a\u51e0\u4e2a\u5c0f\u7c7b\uff1a<\/p>\n<p><strong>\u6574\u578b\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>\u6574\u578b\u6570\u636e\u7c7b\u578b\u4e13\u95e8\u7528\u6765\u5b58\u50a8\u6574\u6570\uff0c\u5c31\u50cf\u6211\u4eec\u6570\u5b66\u4e2d\u5b66\u4e60\u7684\u6574\u6570\u4e00\u6837\uff1a&#8230;\uff0c-3\uff0c-2\uff0c-1\uff0c0\uff0c1\uff0c2\uff0c3\uff0c&#8230;<\/p>\n<p>\u5728\u6574\u578b\u5bb6\u65cf\u4e2d\uff0c\u6709\u597d\u51e0\u4e2a\u6210\u5458\uff0c\u5b83\u4eec\u7684\u533a\u522b\u4e3b\u8981\u5728\u4e8e\u80fd\u591f\u5b58\u50a8\u7684\u6570\u503c\u8303\u56f4\u4e0d\u540c\uff1a<\/p>\n<ul>\n<li><code>int<\/code>\uff1a\u8fd9\u662f\u6700\u5e38\u7528\u7684\u6574\u578b\uff0c\u5c31\u50cf\u5bb6\u65cf\u4e2d\u7684&#8221;\u957f\u5b50&#8221;\uff0c\u662f\u6574\u578b\u5bb6\u65cf\u7684\u4ee3\u8868\u3002\u5b83\u901a\u5e38\u53ef\u4ee5\u5b58\u50a8-2147483648\u52302147483647\u4e4b\u95f4\u7684\u6574\u6570\u3002\u4e3a\u4ec0\u4e48\u662f\u8fd9\u4e2a\u8303\u56f4\u5462\uff1f\u8fd9\u4e0e\u8ba1\u7b97\u673a\u7684\u5185\u90e8\u5b58\u50a8\u65b9\u5f0f\u6709\u5173\uff0c\u6211\u4eec\u540e\u9762\u4f1a\u8be6\u7ec6\u89e3\u91ca\u3002<\/li>\n<li><code>short<\/code>\uff1a\u8fd9\u662f&#8221;\u5c0f\u5f1f\u5f1f&#8221;\uff0c\u80fd\u5b58\u50a8\u7684\u6570\u503c\u8303\u56f4\u6bd4<code>int<\/code>\u5c0f\uff0c\u901a\u5e38\u662f-32768\u523032767\u3002\u867d\u7136\u8303\u56f4\u5c0f\uff0c\u4f46\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u4e5f\u66f4\u5c11\uff0c\u5728\u5185\u5b58\u73cd\u8d35\u7684\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u5f88\u6709\u7528\u3002<\/li>\n<li><code>long<\/code>\uff1a\u8fd9\u662f&#8221;\u5927\u54e5\u54e5&#8221;\uff0c\u80fd\u5b58\u50a8\u7684\u6570\u503c\u8303\u56f4\u6bd4<code>int<\/code>\u5927\u3002\u5728\u4e0d\u540c\u7684\u7cfb\u7edf\u4e2d\uff0c<code>long<\/code>\u7684\u5927\u5c0f\u53ef\u80fd\u4e0d\u540c\uff0c\u4f46\u5b83\u81f3\u5c11\u548c<code>int<\/code>\u4e00\u6837\u5927\u3002<\/li>\n<li><code>long long<\/code>\uff1a\u8fd9\u662f&#8221;\u8d85\u7ea7\u5927\u54e5&#8221;\uff0c\u80fd\u5b58\u50a8\u975e\u5e38\u5927\u7684\u6574\u6570\uff0c\u8303\u56f4\u901a\u5e38\u4ece-9223372036854775808\u52309223372036854775807\u3002<\/li>\n<\/ul>\n<p>\u6bcf\u79cd\u6574\u578b\u8fd8\u53ef\u4ee5\u52a0\u4e0a<code>unsigned<\/code>\u4fee\u9970\u7b26\uff0c\u8868\u793a&#8221;\u65e0\u7b26\u53f7&#8221;\uff0c\u4e5f\u5c31\u662f\u53ea\u80fd\u5b58\u50a8\u975e\u8d1f\u6570\uff080\u548c\u6b63\u6570\uff09\u3002\u8fd9\u5c31\u50cf\u628a\u8d1f\u6570\u7684\u5b58\u50a8\u7a7a\u95f4\u4e5f\u7528\u6765\u5b58\u50a8\u6b63\u6570\uff0c\u6240\u4ee5\u65e0\u7b26\u53f7\u7c7b\u578b\u80fd\u5b58\u50a8\u7684\u6b63\u6570\u8303\u56f4\u4f1a\u7ffb\u500d\u3002<\/p>\n<p><strong>\u6d6e\u70b9\u578b\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>\u6d6e\u70b9\u578b\u7528\u6765\u5b58\u50a8\u5c0f\u6570\uff0c\u6bd4\u59823.14\uff0c2.718\uff0c0.5\u7b49\u7b49\u3002\u4e3a\u4ec0\u4e48\u53eb&#8221;\u6d6e\u70b9&#8221;\u5462\uff1f\u8fd9\u662f\u56e0\u4e3a\u5c0f\u6570\u70b9\u7684\u4f4d\u7f6e\u662f&#8221;\u6d6e\u52a8&#8221;\u7684\uff0c\u53ef\u4ee5\u5728\u6570\u5b57\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\u3002<\/p>\n<ul>\n<li><code>float<\/code>\uff1a\u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff0c\u5c31\u50cf\u7528\u666e\u901a\u7684\u5c3a\u5b50\u6d4b\u91cf\u957f\u5ea6\uff0c\u7cbe\u5ea6\u6709\u9650\u4f46\u591f\u7528\u3002\u5b83\u901a\u5e38\u80fd\u63d0\u4f9b\u5927\u7ea66-7\u4f4d\u6709\u6548\u6570\u5b57\u7684\u7cbe\u5ea6\u3002<\/li>\n<li><code>double<\/code>\uff1a\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff0c\u5c31\u50cf\u7528\u7cbe\u5bc6\u7684\u6e38\u6807\u5361\u5c3a\u6d4b\u91cf\uff0c\u7cbe\u5ea6\u66f4\u9ad8\u3002\u5b83\u901a\u5e38\u80fd\u63d0\u4f9b\u5927\u7ea615-16\u4f4d\u6709\u6548\u6570\u5b57\u7684\u7cbe\u5ea6\u3002\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f7f\u7528<code>double<\/code>\u6765\u5904\u7406\u5c0f\u6570\u3002<\/li>\n<li><code>long double<\/code>\uff1a\u6269\u5c55\u7cbe\u5ea6\u6d6e\u70b9\u6570\uff0c\u7cbe\u5ea6\u6700\u9ad8\uff0c\u4f46\u5728\u4e0d\u540c\u7cfb\u7edf\u4e2d\u7684\u5177\u4f53\u5b9e\u73b0\u53ef\u80fd\u4e0d\u540c\u3002<\/li>\n<\/ul>\n<p><strong>\u5b57\u7b26\u578b\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p><code>char<\/code>\u7c7b\u578b\u7528\u6765\u5b58\u50a8\u5355\u4e2a\u5b57\u7b26\uff0c\u6bd4\u5982\u5b57\u6bcd&#8217;A&#8217;\uff0c\u6570\u5b57&#8217;5&#8217;\uff0c\u6807\u70b9\u7b26\u53f7&#8217;!&#8217;\u7b49\u7b49\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5b57\u7b26\u8981\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\uff0c\u6bd4\u5982&#8217;A&#8217;\uff0c\u800c\u4e0d\u662f&#8221;A&#8221;\u3002<\/p>\n<p>\u6709\u8da3\u7684\u662f\uff0c\u5728\u8ba1\u7b97\u673a\u5185\u90e8\uff0c\u5b57\u7b26\u5b9e\u9645\u4e0a\u662f\u4ee5\u6570\u5b57\u7684\u5f62\u5f0f\u5b58\u50a8\u7684\u3002\u6bcf\u4e2a\u5b57\u7b26\u90fd\u5bf9\u5e94\u4e00\u4e2a\u6570\u5b57\u7f16\u7801\uff0c\u6bd4\u5982\u5b57\u6bcd&#8217;A&#8217;\u5bf9\u5e94\u6570\u5b5765\uff0c\u5b57\u6bcd&#8217;B&#8217;\u5bf9\u5e94\u6570\u5b5766\u3002\u8fd9\u5957\u7f16\u7801\u6807\u51c6\u53eb\u505aASCII\u7801\u3002\u8fd9\u5c31\u50cf\u6bcf\u4e2a\u6c49\u5b57\u90fd\u6709\u4e00\u4e2a\u62fc\u97f3\u7f16\u7801\u4e00\u6837\uff0c\u8ba1\u7b97\u673a\u7528\u6570\u5b57\u6765\u7f16\u7801\u5b57\u7b26\u3002<\/p>\n<p><strong>2. \u6784\u9020\u6570\u636e\u7c7b\u578b\u8be6\u89e3<\/strong><\/p>\n<p>\u6784\u9020\u6570\u636e\u7c7b\u578b\u662f\u7531\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7ec4\u5408\u800c\u6210\u7684\u66f4\u590d\u6742\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5c31\u50cf\u7528\u7816\u5757\u5efa\u9020\u623f\u5b50\u4e00\u6837\uff0c\u7528\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6784\u9020\u66f4\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p><strong>\u6570\u7ec4\u7c7b\u578b<\/strong><\/p>\n<p>\u6570\u7ec4\u5c31\u50cf\u662f\u4e00\u6392\u50a8\u7269\u67dc\uff0c\u6bcf\u4e2a\u67dc\u5b50\u91cc\u53ef\u4ee5\u653e\u540c\u6837\u7c7b\u578b\u7684\u4e1c\u897f\u3002\u6bd4\u5982\uff0c\u4e00\u4e2a\u6574\u578b\u6570\u7ec4\u53ef\u4ee5\u5b58\u50a8\u4e00\u7cfb\u5217\u6574\u6570\uff0c\u5c31\u50cf\u4e00\u6392\u67dc\u5b50\u91cc\u90fd\u653e\u7740\u6570\u5b57\u3002<\/p>\n<p>\u6570\u7ec4\u6709\u4e00\u7ef4\u6570\u7ec4\u3001\u4e8c\u7ef4\u6570\u7ec4\u3001\u591a\u7ef4\u6570\u7ec4\u7b49\u3002\u4e00\u7ef4\u6570\u7ec4\u50cf\u662f\u4e00\u6392\u67dc\u5b50\uff0c\u4e8c\u7ef4\u6570\u7ec4\u50cf\u662f\u4e00\u4e2a\u67dc\u5b50\u77e9\u9635\uff08\u884c\u548c\u5217\uff09\uff0c\u4e09\u7ef4\u6570\u7ec4\u50cf\u662f\u4e00\u4e2a\u7acb\u4f53\u7684\u67dc\u5b50\u7ec4\u5408\u3002<\/p>\n<p><strong>\u6307\u9488\u7c7b\u578b<\/strong><\/p>\n<p>\u6307\u9488\u662fC\u8bed\u8a00\u4e2d\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u4f46\u4e5f\u6bd4\u8f83\u96be\u7406\u89e3\u7684\u6982\u5ff5\u3002\u6307\u9488\u5c31\u50cf\u662f\u5730\u5740\u6807\u7b7e\uff0c\u5b83\u4e0d\u76f4\u63a5\u5b58\u50a8\u6570\u636e\uff0c\u800c\u662f\u5b58\u50a8\u6570\u636e\u7684\u5730\u5740\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u4f60\u8981\u544a\u8bc9\u670b\u53cb\u4f60\u5bb6\u5728\u54ea\u91cc\uff0c\u4f60\u4e0d\u4f1a\u628a\u6574\u4e2a\u623f\u5b50\u642c\u8fc7\u53bb\u7ed9\u4ed6\u770b\uff0c\u800c\u662f\u544a\u8bc9\u4ed6\u4f60\u5bb6\u7684\u5730\u5740\u3002\u6307\u9488\u5c31\u662f\u8fd9\u6837\uff0c\u5b83\u5b58\u50a8\u7684\u662f\u6570\u636e\u5728\u5185\u5b58\u4e2d\u7684&#8221;\u5730\u5740&#8221;\u3002<\/p>\n<p><strong>\u7ed3\u6784\u4f53\u7c7b\u578b<\/strong><\/p>\n<p>\u7ed3\u6784\u4f53\u5141\u8bb8\u6211\u4eec\u628a\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u5c31\u50cf\u586b\u5199\u4e00\u5f20\u5b66\u751f\u4fe1\u606f\u8868\u4e00\u6837\uff0c\u53ef\u4ee5\u5305\u542b\u59d3\u540d\uff08\u5b57\u7b26\u4e32\uff09\u3001\u5e74\u9f84\uff08\u6574\u6570\uff09\u3001\u8eab\u9ad8\uff08\u6d6e\u70b9\u6570\uff09\u7b49\u4e0d\u540c\u7c7b\u578b\u7684\u4fe1\u606f\u3002<\/p>\n<p><strong>\u8054\u5408\u4f53\u7c7b\u578b<\/strong><\/p>\n<p>\u8054\u5408\u4f53\u6bd4\u8f83\u7279\u6b8a\uff0c\u5b83\u5141\u8bb8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u5171\u4eab\u540c\u4e00\u5757\u5185\u5b58\u7a7a\u95f4\u3002\u8fd9\u5c31\u50cf\u4e00\u4e2a\u591a\u529f\u80fd\u623f\u95f4\uff0c\u6709\u65f6\u5019\u5f53\u5367\u5ba4\u4f7f\u7528\uff0c\u6709\u65f6\u5019\u5f53\u5ba2\u5385\u4f7f\u7528\uff0c\u4f46\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u6709\u4e00\u79cd\u7528\u9014\u3002<\/p>\n<p><strong>\u679a\u4e3e\u7c7b\u578b<\/strong><\/p>\n<p>\u679a\u4e3e\u7c7b\u578b\u7528\u6765\u8868\u793a\u4e00\u7ec4\u6709\u9650\u7684\u9009\u62e9\uff0c\u6bd4\u5982\u4e00\u5468\u7684\u4e03\u5929\u3001\u4e00\u5e74\u7684\u5341\u4e8c\u4e2a\u6708\u3001\u4ea4\u901a\u706f\u7684\u4e09\u79cd\u989c\u8272\u7b49\u3002\u8fd9\u8ba9\u7a0b\u5e8f\u66f4\u5bb9\u6613\u7406\u89e3\u548c\u7ef4\u62a4\u3002<\/p>\n<p><strong>3. \u81ea\u5b9a\u4e49\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>\u9664\u4e86C\u8bed\u8a00\u63d0\u4f9b\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>typedef<\/code>\u5173\u952e\u5b57\u6765\u5b9a\u4e49\u81ea\u5df1\u7684\u6570\u636e\u7c7b\u578b\u3002\u8fd9\u5c31\u50cf\u7ed9\u6570\u636e\u7c7b\u578b\u8d77\u522b\u540d\u4e00\u6837\uff0c\u8ba9\u7a0b\u5e8f\u66f4\u5bb9\u6613\u7406\u89e3\u3002<\/p>\n<p>\u6bd4\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\uff1a<\/p>\n<pre><code class=\"c\">typedef int StudentAge;  \/\/ \u5b9a\u4e49\u5b66\u751f\u5e74\u9f84\u7c7b\u578b\ntypedef float StudentHeight;  \/\/ \u5b9a\u4e49\u5b66\u751f\u8eab\u9ad8\u7c7b\u578b<\/code><\/pre>\n<p>\u8fd9\u6837\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528<code>StudentAge<\/code>\u548c<code>StudentHeight<\/code>\u5c31\u66f4\u5bb9\u6613\u7406\u89e3\u8fd9\u4e9b\u53d8\u91cf\u7684\u7528\u9014\u3002<\/p>\n<h4>2.1.2 \u6570\u636e\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8<\/h4>\n<p><strong>1. \u5185\u5b58\u7684\u57fa\u672c\u6982\u5ff5<\/strong><\/p>\n<p>\u8981\u7406\u89e3\u6570\u636e\u5728\u5185\u5b58\u4e2d\u7684\u5b58\u50a8\uff0c\u6211\u4eec\u9996\u5148\u8981\u4e86\u89e3\u4ec0\u4e48\u662f\u5185\u5b58\u3002\u8ba1\u7b97\u673a\u7684\u5185\u5b58\u5c31\u50cf\u4e00\u4e2a\u5de8\u5927\u7684\u50a8\u7269\u67dc\uff0c\u6709\u65e0\u6570\u4e2a\u5c0f\u683c\u5b50\uff0c\u6bcf\u4e2a\u683c\u5b50\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u53f7\uff08\u5730\u5740\uff09\uff0c\u53ef\u4ee5\u5b58\u50a8\u4e00\u4e2a\u5b57\u8282\u7684\u6570\u636e\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b\u4e00\u4e2a\u5de8\u5927\u7684\u90ae\u5c40\uff0c\u6709\u65e0\u6570\u4e2a\u90ae\u7bb1\uff0c\u6bcf\u4e2a\u90ae\u7bb1\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u53f7\u3002\u5f53\u4f60\u8981\u5bc4\u4fe1\u65f6\uff0c\u9700\u8981\u77e5\u9053\u6536\u4fe1\u4eba\u7684\u90ae\u7bb1\u7f16\u53f7\uff1b\u5f53\u4f60\u8981\u53d6\u4fe1\u65f6\uff0c\u4e5f\u9700\u8981\u77e5\u9053\u81ea\u5df1\u7684\u90ae\u7bb1\u7f16\u53f7\u3002\u8ba1\u7b97\u673a\u5185\u5b58\u7684\u5de5\u4f5c\u539f\u7406\u5c31\u662f\u8fd9\u6837\uff0c\u6bcf\u4e2a\u6570\u636e\u90fd\u5b58\u50a8\u5728\u7279\u5b9a\u7f16\u53f7\u7684&#8221;\u90ae\u7bb1&#8221;\u91cc\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000047485230\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000047485231\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><strong>2. \u5b57\u8282\u548c\u4f4d\u7684\u6982\u5ff5<\/strong><\/p>\n<p>\u5728\u6df1\u5165\u4e86\u89e3\u6570\u636e\u5b58\u50a8\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u7406\u89e3\u4e24\u4e2a\u57fa\u672c\u6982\u5ff5\uff1a\u4f4d\uff08bit\uff09\u548c\u5b57\u8282\uff08byte\uff09\u3002<\/p>\n<p><strong>\u4f4d\uff08bit\uff09<\/strong>\u662f\u8ba1\u7b97\u673a\u4e2d\u6700\u5c0f\u7684\u6570\u636e\u5355\u4f4d\uff0c\u5b83\u53ea\u80fd\u5b58\u50a80\u62161\u8fd9\u4e24\u4e2a\u503c\u3002\u8fd9\u5c31\u50cf\u4e00\u4e2a\u5f00\u5173\uff0c\u53ea\u6709&#8221;\u5f00&#8221;\u548c&#8221;\u5173&#8221;\u4e24\u79cd\u72b6\u6001\u3002\u4f4d\u7684\u82f1\u6587&#8221;bit&#8221;\u5b9e\u9645\u4e0a\u662f&#8221;binary digit&#8221;\uff08\u4e8c\u8fdb\u5236\u6570\u5b57\uff09\u7684\u7f29\u5199\u3002<\/p>\n<p><strong>\u5b57\u8282\uff08byte\uff09<\/strong>\u75318\u4e2a\u4f4d\u7ec4\u6210\uff0c\u662f\u8ba1\u7b97\u673a\u4e2d\u57fa\u672c\u7684\u5b58\u50a8\u5355\u4f4d\u3002\u4e00\u4e2a\u5b57\u8282\u53ef\u4ee5\u5b58\u50a8256\u79cd\u4e0d\u540c\u7684\u503c\uff08\u4ece00000000\u523011111111\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u76840\u5230255\uff09\u3002\u4e3a\u4ec0\u4e48\u662f8\u4e2a\u4f4d\u5462\uff1f\u8fd9\u662f\u5386\u53f2\u4e0a\u5f62\u6210\u7684\u6807\u51c6\uff0c8\u4e2a\u4f4d\u6070\u597d\u53ef\u4ee5\u8868\u793a\u4e00\u4e2a\u82f1\u6587\u5b57\u7b26\u3002<\/p>\n<p><strong>3. \u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u5b58\u50a8\u7a7a\u95f4<\/strong><\/p>\n<p>\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u5728\u5185\u5b58\u4e2d\u5360\u7528\u7684\u7a7a\u95f4\u662f\u4e0d\u540c\u7684\uff0c\u8fd9\u5c31\u50cf\u4e0d\u540c\u5927\u5c0f\u7684\u7269\u54c1\u9700\u8981\u4e0d\u540c\u5927\u5c0f\u7684\u76d2\u5b50\u6765\u88c5\u4e00\u6837\u3002<\/p>\n<p><strong>\u5b57\u7b26\u578b\uff08char\uff09<\/strong><\/p>\n<p><code>char<\/code>\u7c7b\u578b\u901a\u5e38\u5360\u75281\u4e2a\u5b57\u8282\u7684\u7a7a\u95f4\u3002\u4e00\u4e2a\u5b57\u8282\u76848\u4e2a\u4f4d\u53ef\u4ee5\u8868\u793a256\u79cd\u4e0d\u540c\u7684\u503c\uff0c\u8fd9\u8db3\u591f\u8868\u793a\u6240\u6709\u7684ASCII\u5b57\u7b26\uff08\u5305\u62ec\u5927\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u6807\u70b9\u7b26\u53f7\u7b49\uff09\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u6211\u4eec\u7528\u4e00\u4e2a\u5c0f\u76d2\u5b50\u6765\u88c5\u4e00\u4e2a\u5b57\u7b26\uff0c\u8fd9\u4e2a\u76d2\u5b50\u521a\u597d\u591f\u653e\u4e0b\u4e00\u4e2a\u5b57\u7b26\uff0c\u4e0d\u591a\u4e0d\u5c11\u3002<\/p>\n<p><strong>\u6574\u578b<\/strong><\/p>\n<p>\u4e0d\u540c\u7684\u6574\u578b\u5360\u7528\u4e0d\u540c\u7684\u5185\u5b58\u7a7a\u95f4\uff1a<\/p>\n<ul>\n<li><code>short<\/code>\u901a\u5e38\u5360\u75282\u4e2a\u5b57\u8282\uff0816\u4f4d\uff09\uff0c\u53ef\u4ee5\u8868\u793a65536\u79cd\u4e0d\u540c\u7684\u503c\u3002\u5982\u679c\u662f\u6709\u7b26\u53f7\u7684\uff0c\u8303\u56f4\u662f-32768\u523032767\uff1b\u5982\u679c\u662f\u65e0\u7b26\u53f7\u7684\uff0c\u8303\u56f4\u662f0\u523065535\u3002<\/li>\n<li><code>int<\/code>\u5728\u73b0\u4ee3\u7cfb\u7edf\u4e2d\u901a\u5e38\u5360\u75284\u4e2a\u5b57\u8282\uff0832\u4f4d\uff09\uff0c\u53ef\u4ee5\u8868\u793a\u7ea642\u4ebf\u79cd\u4e0d\u540c\u7684\u503c\u3002<\/li>\n<li><code>long<\/code>\u7684\u5927\u5c0f\u53d6\u51b3\u4e8e\u7cfb\u7edf\uff0c\u572832\u4f4d\u7cfb\u7edf\u4e2d\u901a\u5e38\u662f4\u4e2a\u5b57\u8282\uff0c\u572864\u4f4d\u7cfb\u7edf\u4e2d\u901a\u5e38\u662f8\u4e2a\u5b57\u8282\u3002<\/li>\n<li><code>long long<\/code>\u901a\u5e38\u5360\u75288\u4e2a\u5b57\u8282\uff0864\u4f4d\uff09\uff0c\u53ef\u4ee5\u8868\u793a\u975e\u5e38\u5927\u7684\u6570\u503c\u8303\u56f4\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u5c31\u50cf\u6211\u4eec\u6709\u4e0d\u540c\u5927\u5c0f\u7684\u76d2\u5b50\uff1a\u5c0f\u76d2\u5b50\u88c5\u5c0f\u7269\u54c1\uff0c\u5927\u76d2\u5b50\u88c5\u5927\u7269\u54c1\u3002\u5982\u679c\u6211\u4eec\u77e5\u9053\u8981\u88c5\u7684\u7269\u54c1\u4e0d\u5927\uff0c\u5c31\u4e0d\u9700\u8981\u6d6a\u8d39\u7a7a\u95f4\u4f7f\u7528\u5927\u76d2\u5b50\u3002<\/p>\n<p><strong>\u6d6e\u70b9\u578b<\/strong><\/p>\n<ul>\n<li><code>float<\/code>\u901a\u5e38\u5360\u75284\u4e2a\u5b57\u8282\uff0c\u6309\u7167IEEE 754\u6807\u51c6\u7684\u5355\u7cbe\u5ea6\u683c\u5f0f\u5b58\u50a8\u3002<\/li>\n<li><code>double<\/code>\u901a\u5e38\u5360\u75288\u4e2a\u5b57\u8282\uff0c\u6309\u7167IEEE 754\u6807\u51c6\u7684\u53cc\u7cbe\u5ea6\u683c\u5f0f\u5b58\u50a8\u3002<\/li>\n<\/ul>\n<p>\u6d6e\u70b9\u6570\u7684\u5b58\u50a8\u6bd4\u6574\u6570\u590d\u6742\u5f97\u591a\uff0c\u5b83\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\uff1a\u7b26\u53f7\u4f4d\u3001\u6307\u6570\u4f4d\u548c\u5c3e\u6570\u4f4d\u3002\u8fd9\u5c31\u50cf\u79d1\u5b66\u8ba1\u6570\u6cd5\u4e00\u6837\uff0c\u6bd4\u59823.14\u00d710\u00b2\uff0c\u5176\u4e2d3.14\u662f\u5c3e\u6570\uff0c2\u662f\u6307\u6570\uff0c\u7b26\u53f7\u662f\u6b63\u53f7\u3002<\/p>\n<p><strong>4. \u6570\u636e\u7684\u4e8c\u8fdb\u5236\u8868\u793a<\/strong><\/p>\n<p>\u8ba1\u7b97\u673a\u5185\u90e8\u6240\u6709\u6570\u636e\u90fd\u662f\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u5b58\u50a8\u7684\uff0c\u4e5f\u5c31\u662f\u53ea\u75280\u548c1\u6765\u8868\u793a\u3002\u8fd9\u5c31\u50cf\u7528\u83ab\u5c14\u65af\u7535\u7801\u6765\u4f20\u9012\u4fe1\u606f\u4e00\u6837\uff0c\u53ea\u7528&#8221;\u6ef4&#8221;\u548c&#8221;\u55d2&#8221;\u4e24\u79cd\u7b26\u53f7\u5c31\u80fd\u8868\u793a\u6240\u6709\u7684\u6587\u5b57\u3002<\/p>\n<p><strong>\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a<\/strong><\/p>\n<p>\u6b63\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u6bd4\u8f83\u76f4\u89c2\uff0c\u5c31\u662f\u5c06\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u6570\u3002\u6bd4\u5982\uff1a<\/p>\n<ul>\n<li>\u5341\u8fdb\u5236\u76845\u5728\u4e8c\u8fdb\u5236\u4e2d\u662f101<\/li>\n<li>\u5341\u8fdb\u5236\u768410\u5728\u4e8c\u8fdb\u5236\u4e2d\u662f1010<\/li>\n<\/ul>\n<p>\u8d1f\u6574\u6570\u7684\u8868\u793a\u7a0d\u5fae\u590d\u6742\u4e00\u4e9b\uff0c\u5927\u591a\u6570\u7cfb\u7edf\u4f7f\u7528&#8221;\u4e8c\u8fdb\u5236\u8865\u7801&#8221;\u7684\u65b9\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u7684\u597d\u5904\u662f\u53ef\u4ee5\u7528\u540c\u6837\u7684\u7535\u8def\u6765\u5904\u7406\u6b63\u6570\u548c\u8d1f\u6570\u7684\u52a0\u6cd5\u8fd0\u7b97\u3002<\/p>\n<p><strong>\u5b57\u7b26\u7684\u4e8c\u8fdb\u5236\u8868\u793a<\/strong><\/p>\n<p>\u5b57\u7b26\u662f\u901a\u8fc7ASCII\u7801\u6765\u8f6c\u6362\u4e3a\u6570\u5b57\uff0c\u7136\u540e\u518d\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u7684\u3002\u6bd4\u5982\uff1a<\/p>\n<ul>\n<li>\u5b57\u7b26&#8217;A&#8217;\u7684ASCII\u7801\u662f65\uff0c\u4e8c\u8fdb\u5236\u662f01000001<\/li>\n<li>\u5b57\u7b26&#8217;a&#8217;\u7684ASCII\u7801\u662f97\uff0c\u4e8c\u8fdb\u5236\u662f01100001<\/li>\n<li>\u5b57\u7b26&#8217;0&#8217;\u7684ASCII\u7801\u662f48\uff0c\u4e8c\u8fdb\u5236\u662f00110000<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff0c\u5b57\u7b26&#8217;0&#8217;\u548c\u6570\u5b570\u662f\u4e0d\u540c\u7684\u3002\u5b57\u7b26&#8217;0&#8217;\u662f\u4e00\u4e2a\u663e\u793a\u7b26\u53f7\uff0c\u5b83\u7684ASCII\u7801\u662f48\uff1b\u800c\u6570\u5b570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5c31\u662f00000000\u3002<\/p>\n<p><strong>5. \u5185\u5b58\u5bf9\u9f50\u7684\u6982\u5ff5<\/strong><\/p>\n<p>\u5728\u5b9e\u9645\u7684\u5185\u5b58\u5b58\u50a8\u4e2d\uff0c\u8fd8\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u6982\u5ff5\u53eb\u505a&#8221;\u5185\u5b58\u5bf9\u9f50&#8221;\u3002\u8fd9\u662f\u4e3a\u4e86\u63d0\u9ad8\u5185\u5b58\u8bbf\u95ee\u6548\u7387\u800c\u91c7\u7528\u7684\u7b56\u7565\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u5982\u679c\u4f60\u8981\u4ece\u4e66\u67b6\u4e0a\u53d6\u4e66\uff0c\u6574\u9f50\u6446\u653e\u7684\u4e66\u6bd4\u6742\u4e71\u6446\u653e\u7684\u4e66\u66f4\u5bb9\u6613\u627e\u5230\u548c\u53d6\u51fa\u3002\u5185\u5b58\u5bf9\u9f50\u5c31\u662f\u8fd9\u6837\uff0c\u5b83\u8ba9\u6570\u636e\u5728\u5185\u5b58\u4e2d\u6309\u7167\u4e00\u5b9a\u7684\u89c4\u5219\u6574\u9f50\u6446\u653e\u3002<\/p>\n<p>&lt;img src=&quot;https:\/\/lxlinux.superbed.verylink.top\/item\/68465eb958cb8da5c83bd7cd.png&quot; style=&quot;zoom: 33%;&quot; \/&gt;<\/p>\n<p>\u6bd4\u5982\uff0c\u4e00\u4e2a<code>int<\/code>\u7c7b\u578b\u7684\u53d8\u91cf\u901a\u5e38\u8981\u6c42\u5b58\u50a8\u57284\u7684\u500d\u6570\u7684\u5730\u5740\u4e0a\u3002\u5982\u679c\u6709\u4e00\u4e2a<code>char<\/code>\u53d8\u91cf\u5360\u7528\u4e86\u5730\u57401\uff0c\u90a3\u4e48\u4e0b\u4e00\u4e2a<code>int<\/code>\u53d8\u91cf\u4e0d\u4f1a\u4ece\u5730\u57402\u5f00\u59cb\uff0c\u800c\u662f\u4ece\u5730\u57404\u5f00\u59cb\uff0c\u4e2d\u95f4\u7684\u5730\u57402\u548c3\u4f1a\u88ab\u7a7a\u51fa\u6765\u3002<\/p>\n<p>\u8fd9\u6837\u505a\u867d\u7136\u53ef\u80fd\u6d6a\u8d39\u4e00\u4e9b\u5185\u5b58\u7a7a\u95f4\uff0c\u4f46\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u6570\u636e\u8bbf\u95ee\u7684\u901f\u5ea6\u3002\u5728\u7ed3\u6784\u4f53\u4e2d\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u8fdb\u884c\u5185\u5b58\u5bf9\u9f50\uff0c\u6709\u65f6\u5019\u7ed3\u6784\u4f53\u7684\u5b9e\u9645\u5927\u5c0f\u4f1a\u6bd4\u5404\u4e2a\u6210\u5458\u5927\u5c0f\u7684\u603b\u548c\u8981\u5927\u3002<\/p>\n<p><strong>6. \u6808\u533a\u548c\u5806\u533a\u7684\u5b58\u50a8<\/strong><\/p>\n<p>\u7a0b\u5e8f\u4e2d\u7684\u53d8\u91cf\u6839\u636e\u5b9a\u4e49\u65b9\u5f0f\u7684\u4e0d\u540c\uff0c\u4f1a\u88ab\u5b58\u50a8\u5728\u5185\u5b58\u7684\u4e0d\u540c\u533a\u57df\uff1a<\/p>\n<p><strong>\u6808\u533a\u5b58\u50a8<\/strong><\/p>\n<p>\u5c40\u90e8\u53d8\u91cf\uff08\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\uff09\u901a\u5e38\u5b58\u50a8\u5728\u6808\u533a\u3002\u6808\u533a\u5c31\u50cf\u4e00\u645e\u76d8\u5b50\uff0c\u540e\u653e\u7684\u76d8\u5b50\u5728\u4e0a\u9762\uff0c\u5148\u62ff\u8d70\u7684\u4e5f\u662f\u4e0a\u9762\u7684\u76d8\u5b50\uff0c\u8fd9\u53eb\u505a&#8221;\u540e\u8fdb\u5148\u51fa&#8221;\u3002<\/p>\n<p>\u5f53\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u4f1a\u88ab&#8221;\u538b\u5165&#8221;\u6808\u4e2d\uff1b\u5f53\u51fd\u6570\u7ed3\u675f\u65f6\uff0c\u8fd9\u4e9b\u53d8\u91cf\u4f1a\u88ab\u81ea\u52a8&#8221;\u5f39\u51fa&#8221;\u6808\uff0c\u5185\u5b58\u7a7a\u95f4\u4f1a\u88ab\u81ea\u52a8\u56de\u6536\u3002<\/p>\n<p><strong>\u5806\u533a\u5b58\u50a8<\/strong><\/p>\n<p>\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58\uff08\u4f7f\u7528malloc\u7b49\u51fd\u6570\u5206\u914d\u7684\u5185\u5b58\uff09\u5b58\u50a8\u5728\u5806\u533a\u3002\u5806\u533a\u7684\u7ba1\u7406\u6bd4\u6808\u533a\u590d\u6742\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u624b\u52a8\u7533\u8bf7\u548c\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<p><strong>\u5168\u5c40\u533a\u5b58\u50a8<\/strong><\/p>\n<p>\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u5b58\u50a8\u5728\u5168\u5c40\u533a\uff0c\u8fd9\u4e9b\u53d8\u91cf\u5728\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4\u4e00\u76f4\u5b58\u5728\u3002<\/p>\n<h4>2.1.3 \u5b57\u8282\u5e8f\u6982\u5ff5<\/h4>\n<p><strong>1. \u4ec0\u4e48\u662f\u5b57\u8282\u5e8f\uff1f<\/strong><\/p>\n<p>\u5b57\u8282\u5e8f\uff08Byte Order\uff09\u662f\u4e00\u4e2a\u542c\u8d77\u6765\u5f88\u6280\u672f\u5316\u7684\u6982\u5ff5\uff0c\u4f46\u5b9e\u9645\u4e0a\u53ef\u4ee5\u7528\u4e00\u4e2a\u5f88\u7b80\u5355\u7684\u4f8b\u5b50\u6765\u7406\u89e3\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u4f60\u8981\u5728\u7eb8\u4e0a\u5199\u4e0b\u6570\u5b57&#8221;1234&#8243;\u3002\u4f60\u4f1a\u4ece\u5de6\u5230\u53f3\u5199\uff0c\u5148\u51991\uff0c\u518d\u51992\uff0c\u7136\u540e3\uff0c\u6700\u540e4\u3002\u4f46\u662f\uff0c\u5982\u679c\u6709\u4e9b\u4eba\u4e60\u60ef\u4ece\u53f3\u5230\u5de6\u5199\u5b57\uff0c\u4ed6\u4eec\u53ef\u80fd\u4f1a\u5148\u51994\uff0c\u518d\u51993\uff0c\u7136\u540e2\uff0c\u6700\u540e1\uff0c\u6700\u7ec8\u5728\u7eb8\u4e0a\u5448\u73b0\u7684\u53ef\u80fd\u662f&#8221;4321&#8243;\u3002<\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u4e16\u754c\u4e2d\uff0c\u4e5f\u5b58\u5728\u7c7b\u4f3c\u7684\u60c5\u51b5\u3002\u5f53\u4e00\u4e2a\u6570\u636e\u9700\u8981\u591a\u4e2a\u5b57\u8282\u6765\u5b58\u50a8\u65f6\uff0c\u8fd9\u4e9b\u5b57\u8282\u5728\u5185\u5b58\u4e2d\u7684\u6392\u5217\u987a\u5e8f\u5c31\u662f\u5b57\u8282\u5e8f\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>2. \u5927\u7aef\u5e8f\u4e0e\u5c0f\u7aef\u5e8f<\/strong><\/p>\n<p>\u8ba1\u7b97\u673a\u4e16\u754c\u4e2d\u4e3b\u8981\u6709\u4e24\u79cd\u5b57\u8282\u5e8f\uff1a\u5927\u7aef\u5e8f\uff08Big Endian\uff09\u548c\u5c0f\u7aef\u5e8f\uff08Little Endian\uff09\u3002<\/p>\n<p><strong>\u5927\u7aef\u5e8f\uff08Big Endian\uff09<\/strong><\/p>\n<p>\u5927\u7aef\u5e8f\u7684\u6392\u5217\u65b9\u5f0f\u662f\u9ad8\u4f4d\u5b57\u8282\u5b58\u50a8\u5728\u4f4e\u5730\u5740\uff0c\u4f4e\u4f4d\u5b57\u8282\u5b58\u50a8\u5728\u9ad8\u5730\u5740\u3002\u8fd9\u5c31\u50cf\u6211\u4eec\u5e73\u5e38\u5199\u6570\u5b57\u7684\u4e60\u60ef\u4e00\u6837\uff0c\u9ad8\u4f4d\u5728\u524d\uff0c\u4f4e\u4f4d\u5728\u540e\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5341\u516d\u8fdb\u5236\u65700x12345678\u5728\u5927\u7aef\u5e8f\u768432\u4f4d\u7cfb\u7edf\u4e2d\u4f1a\u8fd9\u6837\u5b58\u50a8\uff1a<\/p>\n<ul>\n<li>\u5730\u57401000: 0x12\uff08\u6700\u9ad8\u4f4d\u5b57\u8282\uff09<\/li>\n<li>\u5730\u57401001: 0x34<\/li>\n<li>\u5730\u57401002: 0x56<\/li>\n<li>\u5730\u57401003: 0x78\uff08\u6700\u4f4e\u4f4d\u5b57\u8282\uff09<\/li>\n<\/ul>\n<p>\u5927\u7aef\u5e8f\u7684\u547d\u540d\u6765\u6e90\u4e8e\u300a\u683c\u5217\u4f5b\u6e38\u8bb0\u300b\u4e2d\u7684\u6545\u4e8b\uff0c\u5728\u90a3\u4e2a\u6545\u4e8b\u91cc\uff0c\u6709\u4e9b\u4eba\u4e60\u60ef\u4ece\u5927\u5934\uff08Big End\uff09\u5f00\u59cb\u5403\u9e21\u86cb\u3002<\/p>\n<p><strong>\u5c0f\u7aef\u5e8f\uff08Little Endian\uff09<\/strong><\/p>\n<p>\u5c0f\u7aef\u5e8f\u7684\u6392\u5217\u65b9\u5f0f\u6b63\u597d\u76f8\u53cd\uff0c\u4f4e\u4f4d\u5b57\u8282\u5b58\u50a8\u5728\u4f4e\u5730\u5740\uff0c\u9ad8\u4f4d\u5b57\u8282\u5b58\u50a8\u5728\u9ad8\u5730\u5740\u3002\u8fd9\u5c31\u50cf\u5012\u7740\u5199\u6570\u5b57\u4e00\u6837\u3002<\/p>\n<p>\u540c\u6837\u7684\u5341\u516d\u8fdb\u5236\u65700x12345678\u5728\u5c0f\u7aef\u5e8f\u768432\u4f4d\u7cfb\u7edf\u4e2d\u4f1a\u8fd9\u6837\u5b58\u50a8\uff1a<\/p>\n<ul>\n<li>\u5730\u57401000: 0x78\uff08\u6700\u4f4e\u4f4d\u5b57\u8282\uff09<\/li>\n<li>\u5730\u57401001: 0x56<\/li>\n<li>\u5730\u57401002: 0x34<\/li>\n<li>\u5730\u57401003: 0x12\uff08\u6700\u9ad8\u4f4d\u5b57\u8282\uff09<\/li>\n<\/ul>\n<p>\u5c0f\u7aef\u5e8f\u7684\u547d\u540d\u4e5f\u6765\u6e90\u4e8e\u300a\u683c\u5217\u4f5b\u6e38\u620f\u300b\uff0c\u5bf9\u5e94\u4ece\u5c0f\u5934\uff08Little End\uff09\u5f00\u59cb\u5403\u9e21\u86cb\u7684\u4eba\u3002<\/p>\n<p><strong>4. \u4e3a\u4ec0\u4e48\u4f1a\u6709\u4e0d\u540c\u7684\u5b57\u8282\u5e8f\uff1f<\/strong><\/p>\n<p>\u4f60\u53ef\u80fd\u4f1a\u60f3\uff0c\u4e3a\u4ec0\u4e48\u8981\u6709\u4e24\u79cd\u4e0d\u540c\u7684\u5b57\u8282\u5e8f\u5462\uff1f\u76f4\u63a5\u7edf\u4e00\u6210\u4e00\u79cd\u4e0d\u662f\u66f4\u597d\u5417\uff1f\u8fd9\u5176\u5b9e\u6709\u5386\u53f2\u539f\u56e0\u548c\u6280\u672f\u539f\u56e0\u3002<\/p>\n<p><strong>\u5386\u53f2\u539f\u56e0<\/strong><\/p>\n<p>\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u5382\u5546\u5728\u8bbe\u8ba1\u5904\u7406\u5668\u65f6\uff0c\u57fa\u4e8e\u4e0d\u540c\u7684\u8003\u8651\u9009\u62e9\u4e86\u4e0d\u540c\u7684\u5b57\u8282\u5e8f\u3002\u6bd4\u5982\uff0cIntel\u7684x86\u7cfb\u5217\u5904\u7406\u5668\u91c7\u7528\u5c0f\u7aef\u5e8f\uff0c\u800cMotorola\u768468000\u7cfb\u5217\u5904\u7406\u5668\u91c7\u7528\u5927\u7aef\u5e8f\u3002\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\uff0c\u8fd9\u4e9b\u4e0d\u540c\u7684\u9009\u62e9\u5c31\u56fa\u5316\u4e0b\u6765\u4e86\u3002<\/p>\n<p><strong>\u6280\u672f\u8003\u8651<\/strong><\/p>\n<p>\u4e24\u79cd\u5b57\u8282\u5e8f\u5404\u6709\u4f18\u52bf\uff1a<\/p>\n<p>\u5927\u7aef\u5e8f\u7684\u4f18\u52bf\u662f\u6bd4\u8f83\u76f4\u89c2\uff0c\u7b26\u5408\u4eba\u7c7b\u7684\u9605\u8bfb\u4e60\u60ef\u3002\u5728\u7f51\u7edc\u4f20\u8f93\u4e2d\uff0c\u5927\u7aef\u5e8f\u88ab\u5e7f\u6cdb\u91c7\u7528\uff0c\u6240\u4ee5\u4e5f\u88ab\u79f0\u4e3a&#8221;\u7f51\u7edc\u5b57\u8282\u5e8f&#8221;\u3002<\/p>\n<p>\u5c0f\u7aef\u5e8f\u7684\u4f18\u52bf\u662f\u5728\u8fdb\u884c\u67d0\u4e9b\u6570\u5b66\u8fd0\u7b97\u65f6\u6548\u7387\u66f4\u9ad8\u3002\u6bd4\u5982\uff0c\u5728\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u65f6\uff0c\u5c0f\u7aef\u5e8f\u7cfb\u7edf\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u4f4e\u5730\u5740\u7684\u6570\u636e\uff0c\u4e0d\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u5730\u5740\u3002<\/p>\n<p><strong>5. \u4e0d\u540c\u7cfb\u7edf\u7684\u5b57\u8282\u5e8f<\/strong><\/p>\n<p><strong>\u5e38\u89c1\u7cfb\u7edf\u7684\u5b57\u8282\u5e8f<\/strong><\/p>\n<ul>\n<li>Intel x86\/x64\u7cfb\u5217\uff1a\u5c0f\u7aef\u5e8f<\/li>\n<li>ARM\u5904\u7406\u5668\uff1a\u53ef\u914d\u7f6e\uff0c\u4f46\u901a\u5e38\u4f7f\u7528\u5c0f\u7aef\u5e8f<\/li>\n<li>PowerPC\uff1a\u5927\u7aef\u5e8f<\/li>\n<li>SPARC\uff1a\u5927\u7aef\u5e8f<\/li>\n<li>MIPS\uff1a\u53ef\u914d\u7f6e\uff0c\u53ef\u4ee5\u662f\u5927\u7aef\u5e8f\u6216\u5c0f\u7aef\u5e8f<\/li>\n<\/ul>\n<p><strong>\u7f51\u7edc\u5b57\u8282\u5e8f<\/strong><\/p>\n<p>\u5728\u7f51\u7edc\u901a\u4fe1\u4e2d\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u4e0d\u540c\u7cfb\u7edf\u4e4b\u95f4\u80fd\u591f\u6b63\u786e\u4ea4\u6362\u6570\u636e\uff0c\u89c4\u5b9a\u7edf\u4e00\u4f7f\u7528\u5927\u7aef\u5e8f\uff0c\u8fd9\u88ab\u79f0\u4e3a&#8221;\u7f51\u7edc\u5b57\u8282\u5e8f&#8221;\u3002\u5f53\u6570\u636e\u5728\u7f51\u7edc\u4e2d\u4f20\u8f93\u65f6\uff0c\u53d1\u9001\u65b9\u9700\u8981\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u7f51\u7edc\u5b57\u8282\u5e8f\uff0c\u63a5\u6536\u65b9\u518d\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u672c\u5730\u5b57\u8282\u5e8f\u3002<\/p>\n<p><strong>6. \u5b57\u8282\u5e8f\u7684\u5f71\u54cd<\/strong><\/p>\n<p><strong>\u5bf9\u7a0b\u5e8f\u5458\u7684\u5f71\u54cd<\/strong><\/p>\n<p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u7a0b\u5e8f\u5458\u4e0d\u9700\u8981\u5173\u5fc3\u5b57\u8282\u5e8f\u95ee\u9898\uff0c\u56e0\u4e3a\uff1a<\/p>\n<ol>\n<li>\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u5b57\u8282\u5e8f\u662f\u4e00\u81f4\u7684<\/li>\n<li>C\u8bed\u8a00\u7684\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u5904\u7406\u5927\u90e8\u5206\u5b57\u8282\u5e8f\u95ee\u9898<\/li>\n<li>\u9ad8\u7ea7\u8bed\u8a00\u901a\u5e38\u4f1a\u5c4f\u853d\u8fd9\u4e9b\u5e95\u5c42\u7ec6\u8282<\/li>\n<\/ol>\n<p>\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5b57\u8282\u5e8f\u5c31\u53d8\u5f97\u5f88\u91cd\u8981\uff1a<\/p>\n<p><strong>\u6587\u4ef6\u5b58\u50a8<\/strong><\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u7a0b\u5e8f\u5728\u5c0f\u7aef\u5e8f\u7cfb\u7edf\u4e0a\u521b\u5efa\u4e86\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u7136\u540e\u8fd9\u4e2a\u6587\u4ef6\u88ab\u4f20\u8f93\u5230\u5927\u7aef\u5e8f\u7cfb\u7edf\u4e0a\u8bfb\u53d6\uff0c\u5c31\u53ef\u80fd\u51fa\u73b0\u6570\u636e\u9519\u8bef\u3002<\/p>\n<p>\u6bd4\u5982\uff0c\u6570\u5b571234\u5728\u5c0f\u7aef\u5e8f\u6587\u4ef6\u4e2d\u53ef\u80fd\u5b58\u50a8\u4e3aD2 04\uff08\u5341\u516d\u8fdb\u5236\uff09\uff0c\u4f46\u5728\u5927\u7aef\u5e8f\u7cfb\u7edf\u8bfb\u53d6\u65f6\u53ef\u80fd\u88ab\u89e3\u91ca\u4e3a1234\uff08\u5341\u516d\u8fdb\u5236\uff09\uff0c\u8fd9\u5b8c\u5168\u662f\u9519\u8bef\u7684\u503c\u3002<\/p>\n<p><strong>\u7f51\u7edc\u7f16\u7a0b<\/strong><\/p>\n<p>\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5728\u672c\u5730\u5b57\u8282\u5e8f\u548c\u7f51\u7edc\u5b57\u8282\u5e8f\u4e4b\u95f4\u8f6c\u6362\u3002C\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e13\u95e8\u7684\u51fd\u6570\u6765\u5904\u7406\u8fd9\u79cd\u8f6c\u6362\uff1a<\/p>\n<ul>\n<li><code>htons()<\/code>\uff1a\u4e3b\u673a\u5b57\u8282\u5e8f\u8f6c\u7f51\u7edc\u5b57\u8282\u5e8f\uff08\u77ed\u6574\u578b\uff09<\/li>\n<li><code>htonl()<\/code>\uff1a\u4e3b\u673a\u5b57\u8282\u5e8f\u8f6c\u7f51\u7edc\u5b57\u8282\u5e8f\uff08\u957f\u6574\u578b\uff09<\/li>\n<li><code>ntohs()<\/code>\uff1a\u7f51\u7edc\u5b57\u8282\u5e8f\u8f6c\u4e3b\u673a\u5b57\u8282\u5e8f\uff08\u77ed\u6574\u578b\uff09<\/li>\n<li><code>ntohl()<\/code>\uff1a\u7f51\u7edc\u5b57\u8282\u5e8f\u8f6c\u4e3b\u673a\u5b57\u8282\u5e8f\uff08\u957f\u6574\u578b\uff09<\/li>\n<\/ul>\n<p><strong>\u5d4c\u5165\u5f0f\u7cfb\u7edf<\/strong><\/p>\n<p>\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f00\u53d1\u4e2d\uff0c\u7279\u522b\u662f\u5f53\u9700\u8981\u4e0e\u5176\u4ed6\u7cfb\u7edf\u901a\u4fe1\u6216\u5904\u7406\u7279\u5b9a\u683c\u5f0f\u7684\u6570\u636e\u65f6\uff0c\u5b57\u8282\u5e8f\u95ee\u9898\u5c31\u53d8\u5f97\u5f88\u91cd\u8981\u3002\u7a0b\u5e8f\u5458\u9700\u8981\u660e\u786e\u77e5\u9053\u6570\u636e\u7684\u5b57\u8282\u5e8f\uff0c\u5e76\u8fdb\u884c\u6b63\u786e\u7684\u5904\u7406\u3002<\/p>\n<p><strong>7. \u68c0\u6d4b\u7cfb\u7edf\u5b57\u8282\u5e8f<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u7528\u4e00\u4e2a\u7b80\u5355\u7684C\u7a0b\u5e8f\u6765\u68c0\u6d4b\u5f53\u524d\u7cfb\u7edf\u7684\u5b57\u8282\u5e8f\uff1a<\/p>\n<pre><code class=\"c\">#include &lt;stdio.h&gt;\n\nint main() {\n    int test = 1;\n    char *p = (char*)&amp;test;\n    \n    if (*p == 1) {\n        printf(&quot;\u5f53\u524d\u7cfb\u7edf\u662f\u5c0f\u7aef\u5e8f\/n&quot;);\n    } else {\n        printf(&quot;\u5f53\u524d\u7cfb\u7edf\u662f\u5927\u7aef\u5e8f\/n&quot;);\n    }\n    \n    return 0;\n}<\/code><\/pre>\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u5de5\u4f5c\u539f\u7406\u662f\uff1a\u6574\u65701\u5728\u5185\u5b58\u4e2d\uff0c\u5982\u679c\u662f\u5c0f\u7aef\u5e8f\uff0c\u6700\u4f4e\u5b57\u8282\uff08\u503c\u4e3a1\uff09\u4f1a\u5b58\u50a8\u5728\u6700\u4f4e\u5730\u5740\uff1b\u5982\u679c\u662f\u5927\u7aef\u5e8f\uff0c\u6700\u4f4e\u5b57\u8282\u4f1a\u5b58\u50a8\u5728\u6700\u9ad8\u5730\u5740\u3002\u901a\u8fc7\u68c0\u67e5\u6700\u4f4e\u5730\u5740\u7684\u503c\uff0c\u5c31\u53ef\u4ee5\u5224\u65ad\u5b57\u8282\u5e8f\u3002<\/p>\n<p><strong>8. \u5b57\u8282\u5e8f\u8f6c\u6362\u7684\u5b9e\u73b0<\/strong><\/p>\n<p>\u867d\u7136\u7cfb\u7edf\u63d0\u4f9b\u4e86\u5b57\u8282\u5e8f\u8f6c\u6362\u51fd\u6570\uff0c\u4f46\u4e86\u89e3\u5176\u5b9e\u73b0\u539f\u7406\u4e5f\u5f88\u6709\u610f\u4e49\u3002\u4ee516\u4f4d\u6570\u636e\u7684\u5b57\u8282\u5e8f\u8f6c\u6362\u4e3a\u4f8b\uff1a<\/p>\n<pre><code class=\"c\">unsigned short swap16(unsigned short value) {\n    return ((value &amp; 0xFF00) &gt;&gt; 8) | ((value &amp; 0x00FF) &lt;&lt; 8);\n}<\/code><\/pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u901a\u8fc7\u4f4d\u8fd0\u7b97\u6765\u4ea4\u6362\u9ad8\u4f4e\u5b57\u8282\u7684\u4f4d\u7f6e\uff0c\u4ece\u800c\u5b9e\u73b0\u5b57\u8282\u5e8f\u8f6c\u6362\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047485227\">https:\/\/segmentfault.com\/a\/1190000047485227<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u826f\u8bb8\uff0c\u4e00\u4e2a\u6df1\u8015\u5d4c\u5165\u5f0f 12 \u5e74\u7684\u8001\u5de5\u7a0b\u5e08\uff0c\u524d\u4e16\u754c 500 \u5f3a\u9ad8\u5de5\u3002 \u6211\u82b1\u4e86 3 \u4e2a\u6708\u65f6\u95f4\uff0c\u5199\u4e86\u4e00\u4e2a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021129","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021129"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021129\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}