\u4f46\u4e0d\u63a8\u8350\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\uff0c\u9644\u4e0a\u5e38\u7528\u7684\u4e34\u65f6\u53d8\u91cf\u65b9\u6cd5\u5bf9\u6bd4\u8bf4\u660e\u3002<\/p>\n
void swap(int &a, int &b)\r\n{\r\n int tmp = a;\r\n a = b;\r\n b = tmp;\r\n}<\/pre>\n\u5bf9\u4e8e\u4e34\u65f6\u53d8\u91cf\u6cd5\uff0c\u6bcf\u6b21\u8d4b\u503c\u53ea\u8981\u8bfb\u53d6\u4e00\u4e2a\u53d8\u91cf\u7684\u503c\u5230\u5bc4\u5b58\u5668\uff0c\u7136\u540e\u518d\u4ece\u5bc4\u5b58\u5668\u5199\u56de\u5230\u53e6\u4e00\u4e2a\u53d8\u91cf\u4e2d\u5373\u53ef\uff0c\u524d\u540e\u6d89\u53ca\u4e24\u6b21\u5185\u5b58\u5199\u5165\u64cd\u4f5c\uff1b\u4f46\u662f\u5bf9\u4e8e\u5f02\u6216\u8fd0\u7b97\u64cd\u4f5c\uff0c\u6bcf\u6b21\u90fd\u9700\u8981\u8bfb\u53d6\u4e24\u4e2a\u6570\u636e\u5230\u5bc4\u5b58\u5668\u4e2d\uff0c\u518d\u8fdb\u884c\u8fd0\u7b97\u64cd\u4f5c\uff0c\u4e4b\u540e\u628a\u7ed3\u679c\u5199\u56de\u5230\u53d8\u91cf\u4e2d\uff0c\u524d\u540e\u5171\u9700\u8981\u4e09\u6b21\u5185\u5b58\u5199\u5165\u64cd\u4f5c\u3002\u53e6\u5916\u4e00\u70b9\uff0c\u5f02\u6216\u64cd\u4f5c\u7684\u4ee3\u7801\u53ef\u8bfb\u6027\u5dee\u3002<\/p>\n
\u5982\u679c\u4f7f\u7528C\u8bed\u8a00\u5b9e\u73b0\u4e0a\u8ff0\u4e24\u79cd\u65b9\u6cd5\uff0c\u5e76\u7528gcc\u7f16\u8bd1\u5668\u7f16\u8bd1\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4 gcc -S swap.c \u67e5\u770b\u76f8\u5e94\u7684\u6c47\u7f16\u4ee3\u7801\uff0c\u4e34\u65f6\u53d8\u91cf\u6cd5\u4ee3\u7801\u884c\u6570\u66f4\u5c11\uff0c\u53e6\u5916\u4f7f\u7528 gcc \u7f16\u8bd1\u5668\u65f6\uff0c\u7528\u5f02\u6216\u8fd0\u7b97\u4ea4\u6362\u6570\u7ec4\u4f1a\u51fa\u9519\uff0c\u53c2\u89c1\u94fe\u63a5\u3002<\/p>\n
\u5728\u4e0d\u5f15\u5165\u4e34\u65f6\u53d8\u91cf\u7684\u57fa\u7840\u4e0a\uff0c\u4ea4\u6362\u4e24\u6570\u7684\u503c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4e09\u6b21\u52a0\u51cf\u6cd5\uff0c\u4ee3\u7801\u5982\u4e0b:<\/p>\n
void swap(int &a, int &b)\r\n{\r\n a = a + b;\r\n b = a - b;\r\n a = a - b;\r\n}<\/pre>\n\u8fd9\u79cd\u65b9\u5f0f\u540c\u6837\u9700\u8981\u4e09\u6b21\u5185\u5b58\u5199\u5165\u64cd\u4f5c\uff0c\u540c\u65f6\u4ee3\u7801\u53ef\u8bfb\u6027\u4e5f\u8f83\u5dee\u3002<\/p>\n
\u6700\u540e\u9644\u4e0a\u4e24\u5f20\u4e09\u79cd\u65b9\u6cd5\u7f16\u8bd1\u540e\u5bf9\u5e94\u6c47\u7f16\u4ee3\u7801\u5bf9\u6bd4\u56fe\uff08\u5e73\u53f0\uff1aUbuntu14.04\uff0cgcc 4.8.4\uff09\uff0c\u56fe\u4e2d swap1.c \u6587\u4ef6\u5bf9\u5e94\u4e34\u65f6\u53d8\u91cf\u6cd5\uff0cswap2.c \u6587\u4ef6\u5bf9\u5e94\u52a0\u51cf\u65b9\u6cd5\uff0cswap3.c \u6587\u4ef6\u5bf9\u5e94\u5f02\u6216\u65b9\u6cd5\u3002\u53ef\u4ee5\u770b\u5230\uff0c\u4e34\u65f6\u53d8\u91cf\u6cd5\u7f16\u8bd1\u51fa\u7684\u6c47\u7f16\u4ee3\u7801\u91cf\u6700\u5c11\u5373\u6548\u7387\u66f4\u9ad8\uff0c\u52a0\u51cf\u6cd5\u548c\u5f02\u6216\u65b9\u6cd5\u7684\u533a\u522b\u4ec5\u4ec5\u662f\u8ba1\u7b97\u65b9\u5f0f\u4e0d\u540c\u800c\u5df2\uff0c\u64cd\u4f5c\u6b65\u9aa4\u662f\u4e00\u81f4\u7684\u3002<\/p>\n
\u56fe1: \u4e34\u65f6\u53d8\u91cf\u6cd5\u548c\u52a0\u51cf\u6cd5\u6c47\u7f16\u4ee3\u7801\u5bf9\u6bd4\uff0c\u70b9\u51fb\u56fe\u7247\u67e5\u770b\u5927\u56fe\u3002<\/strong>
\n<\/p>\n\u56fe2: \u5f02\u6216\u65b9\u6cd5\u548c\u52a0\u51cf\u6cd5\u6c47\u7f16\u4ee3\u7801\u5bf9\u6bd4\uff0c\u70b9\u51fb\u56fe\u7247\u67e5\u770b\u5927\u56fe\u3002<\/strong>
\n<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f02\u6216\u8fd0\u7b97\u53ef\u4ee5\u8fbe\u5230\u4ea4\u6362\u4e24\u6570\u7684\u76ee\u7684\uff0c\u4ee3\u7801\u5982\u4e0b: void swap(int &a, int &b) { a = a […]<\/p>\n","protected":false},"author":1470,"featured_media":219135,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-219131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=219131"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219131\/revisions"}],"predecessor-version":[{"id":219138,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219131\/revisions\/219138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/219135"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=219131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=219131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=219131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}