{"id":296995,"date":"2024-05-20T16:16:16","date_gmt":"2024-05-20T08:16:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/296995.html"},"modified":"2024-05-20T16:16:43","modified_gmt":"2024-05-20T08:16:43","slug":"whilea-b-%e6%98%af%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/296995.html","title":{"rendered":"while(*a  ==*b  )\u662f\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27144653\/4b3de2f9-b627-4783-8fe8-e7c4033e942c.webp\" alt=\"while(*a  ==*b  )\u662f\u4ec0\u4e48\u610f\u601d\" \/><\/p>\n<p><p><strong>\u5728C\u8bed\u8a00\u4e2d\uff0c<code>while(*a == *b)<\/code>\u8868\u793a\u5728<code>while<\/code>\u5faa\u73af\u6761\u4ef6\u4e0b\uff0c\u53ea\u8981\u6307\u9488<code>a<\/code>\u6240\u6307\u5411\u4f4d\u7f6e\u7684\u503c\u4e0e\u6307\u9488<code>b<\/code>\u6240\u6307\u5411\u4f4d\u7f6e\u7684\u503c\u76f8\u7b49\uff0c\u5faa\u73af\u5c31\u4f1a\u6301\u7eed\u6267\u884c<\/strong>\u3002\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u5e38\u5e38\u7528\u4e8e\u5b57\u7b26\u4e32\u6bd4\u8f83\u7b49\u64cd\u4f5c\u4e2d\uff0c\u4f8b\u5982\u5728C\u6807\u51c6\u5e93\u51fd\u6570<code>strcmp<\/code>\u7684\u5b9e\u73b0\u4e2d\u5c31\u53ef\u80fd\u4f1a\u4f7f\u7528\u5230\u7c7b\u4f3c\u7684\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p><p>\u8981\u8be6\u7ec6\u7406\u89e3<code>while(*a == *b)<\/code>\u7684\u542b\u4e49\uff0c\u6211\u4eec\u9700\u8981\u5148\u660e\u767d\u6307\u9488\u548c\u89e3\u5f15\u7528\u7684\u6982\u5ff5\u3002\u5728\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u4e2d\uff0c<code>a<\/code>\u548c<code>b<\/code>\u662f\u6307\u5411\u67d0\u79cd\u7c7b\u578b\uff08\u901a\u5e38\u662f<code>char<\/code>\u578b\uff0c\u5373\u5b57\u7b26\u578b\uff09\u7684\u6307\u9488\u53d8\u91cf\u3002\u7b26\u53f7<code>*<\/code>\u662f\u89e3\u5f15\u7528\u64cd\u4f5c\u7b26\uff0c\u8868\u793a\u83b7\u53d6\u6307\u9488\u6240\u6307\u5411\u5185\u5b58\u4f4d\u7f6e\u7684\u503c\u3002\u56e0\u6b64\uff0c\u5728\u6bcf\u6b21\u5faa\u73af\u8fed\u4ee3\u4e2d\uff0c\u7a0b\u5e8f\u4f1a\u6bd4\u8f83\u8fd9\u4e24\u4e2a\u5730\u5740\u4e0a\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002\u5982\u679c\u5b83\u4eec\u90fd\u6307\u5411\u5b57\u7b26\u4e32\u7684\u8bdd\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6bd4\u8f83\u5c31\u662f\u5728\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5f53\u524d\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u4ee5null (&#039;\\0&#039;)\u7ec8\u6b62\u7684C\u98ce\u683c\u5b57\u7b26\u4e32\uff0c\u8fd9\u4e2a\u5faa\u73af\u53ef\u4ee5\u7528\u6765\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49\u3002\u5faa\u73af\u4f1a\u4e00\u76f4\u6267\u884c\uff0c\u76f4\u5230\u9047\u5230\u5b57\u7b26\u4e32\u7684\u7ed3\u5c3e\uff08\u5373\u9047\u5230\u7b2c\u4e00\u4e2a\u4e0d\u76f8\u7b49\u7684\u5b57\u7b26\u6216\u4efb\u4e00\u5b57\u7b26\u4e32\u7684\u7ed3\u5c3enull\u5b57\u7b26\uff09\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u6307\u9488\u548c\u89e3\u5f15\u7528<\/p>\n<p>\u6307\u9488\u662f\u5b58\u50a8\u53e6\u4e00\u4e2a\u53d8\u91cf\u7684\u5185\u5b58\u5730\u5740\u7684\u53d8\u91cf\uff0c\u800c\u89e3\u5f15\u7528\u6307\u9488\u662f\u83b7\u53d6\u90a3\u4e2a\u5730\u5740\u4e0a\u5b58\u50a8\u7684\u6570\u636e\u3002\u5728C\u8bed\u8a00\u4e2d\uff0c\u6307\u9488\u5177\u6709\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u8868\u793a\u6307\u9488\u6307\u5411\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5982<code>int *<\/code>\u662f\u6574\u6570\u6307\u9488\uff0c<code>char *<\/code>\u662f\u5b57\u7b26\u6307\u9488\u3002\u4f7f\u7528<code>*<\/code>\u64cd\u4f5c\u7b26\u53ef\u4ee5\u89e3\u5f15\u7528\u8fd9\u4e9b\u6307\u9488\uff0c\u4e5f\u5c31\u662f\u83b7\u53d6\u6216\u8bbe\u7f6e\u6307\u9488\u6307\u5411\u5730\u5740\u4e0a\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5b57\u7b26\u4e32\u7684\u9010\u5b57\u7b26\u6bd4\u8f83<\/p>\n<p>\u5b57\u7b26\u4e32\u5728C\u8bed\u8a00\u4e2d\u901a\u8fc7\u5b57\u7b26\u6570\u7ec4\u8868\u793a\uff0c\u5e76\u4ee5null\u5b57\u7b26\u6807\u8bc6\u7ed3\u675f\u3002\u4f7f\u7528\u6307\u9488\u8bbf\u95ee\u548c\u6bd4\u8f83\u5b57\u7b26\u4e32\u65f6\uff0c\u7ecf\u5e38\u9700\u8981\u9010\u5b57\u7b26\u5730\u8fdb\u884c\u3002<code>while(*a == *b)<\/code>\u5faa\u73af\u53ef\u4ee5\u9010\u4e2a\u5b57\u7b26\u5730\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u76f4\u5230\u627e\u5230\u4e0d\u540c\u7684\u5b57\u7b26\u6216\u8005\u5230\u8fbe\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5faa\u73af\u7684\u5e94\u7528\u573a\u666f<\/p>\n<p>\u8fd9\u79cd\u7c7b\u578b\u7684\u5faa\u73af\u5e38\u89c1\u4e8e\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u4e2d\uff0c\u5982\u81ea\u5b9a\u4e49\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\u51fd\u6570<code>strcmp<\/code>\u5b9e\u73b0\uff0c\u6216\u662f\u67e5\u627e\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5171\u540c\u524d\u7f00\u3002\u901a\u8fc7\u6307\u9488\u64cd\u4f5c\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u904d\u5386\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u5fc5\u62c5\u5fc3\u6570\u7ec4\u4e0b\u6807\u8d8a\u754c\u7b49\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5faa\u73af\u7684\u7ec6\u8282\u5904\u7406<\/p>\n<p>\u5728\u4f7f\u7528\u8fd9\u79cd\u5faa\u73af\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u88ab\u6bd4\u8f83\u7684\u5b57\u7b26\u4e32\u90fd\u662f\u4ee5null\u7ec8\u6b62\u7684\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8d8a\u754c\u8bbf\u95ee\u5185\u5b58\u3002\u540c\u65f6\uff0c\u5faa\u73af\u7ed3\u675f\u7684\u6761\u4ef6\u8981\u7cbe\u786e\u5b9a\u4e49\uff0c\u4ee5\u9632\u6b62\u65e0\u9650\u5faa\u73af\u6216\u63d0\u524d\u7ec8\u6b62\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001C\u8bed\u8a00\u6807\u51c6\u5e93\u51fd\u6570\u4e2d\u7684\u5e94\u7528<\/p>\n<p>C\u6807\u51c6\u5e93\u4e2d\u7684\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\uff0c\u5982<code>strcmp<\/code>\u548c<code>strncmp<\/code>\uff0c\u5e95\u5c42\u539f\u7406\u57fa\u672c\u4e0a\u90fd\u662f\u901a\u8fc7\u6307\u9488\u64cd\u4f5c\u6765\u9010\u4e00\u6bd4\u5bf9\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u3002\u8fd9\u4e9b\u51fd\u6570\u65e0\u7591\u662f<code>while(*a == *b)<\/code>\u8868\u8fbe\u5f0f\u4f7f\u7528\u7684\u5178\u578b\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u6027\u80fd\u4f18\u5316<\/p>\n<p>\u5728\u5bf9\u6027\u80fd\u6709\u4e25\u683c\u8981\u6c42\u7684\u573a\u5408\uff0c\u9010\u5b57\u7b26\u6bd4\u8f83\u53ef\u80fd\u9700\u8981\u8fdb\u884c\u4f18\u5316\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u8f83\u957f\u7684\u5b57\u7b26\u4e32\uff0c\u5728\u4fdd\u8bc1\u5b89\u5168\u7684\u524d\u63d0\u4e0b\uff0c\u53ef\u80fd\u4f1a\u91c7\u7528\u4e00\u4e9b\u66f4\u9ad8\u6548\u7684\u7b97\u6cd5\u6216\u5229\u7528\u786c\u4ef6\u7279\u6027\u6765\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u5b89\u5168\u6027\u8003\u8651<\/p>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u76f4\u63a5\u5904\u7406\u6307\u9488\u548c\u5185\u5b58\u9700\u8981\u683c\u5916\u5c0f\u5fc3\uff0c\u4ee5\u907f\u514d\u7f13\u51b2\u533a\u6ea2\u51fa\u3001\u7a7a\u6307\u9488\u89e3\u5f15\u7528\u548c\u5176\u4ed6\u5b89\u5168\u9690\u60a3\u3002\u4e00\u4e9b\u73b0\u4ee3\u7f16\u7a0b\u8bed\u8a00\u901a\u8fc7\u5185\u5b58\u5b89\u5168\u548c\u66f4\u9ad8\u7ea7\u7684\u5b57\u7b26\u4e32\u62bd\u8c61\u6765\u907f\u514d\u8fd9\u7c7b\u4f4e\u7ea7\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3\u800c\u8a00\uff0c<code>while(*a == *b)<\/code>\u662f\u4e00\u4e2a\u5173\u4e8e\u6307\u9488\u8fd0\u7b97\u548c\u5faa\u73af\u63a7\u5236\u7684\u57fa\u672c\u8868\u8fbe\u5f0f\uff0c\u5728C\u8bed\u8a00\u4e2d\u7ecf\u5e38\u7528\u6765\u6bd4\u8f83\u5b57\u7b26\u4e32\u6216\u8fdb\u884c\u5176\u4ed6\u7b26\u53f7\u7ea7\u522b\u7684\u6570\u636e\u6bd4\u8f83\u3002\u638c\u63e1\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u542b\u4e49\u5bf9\u7406\u89e3C\u8bed\u8a00\u7684\u5185\u5b58\u64cd\u4f5c\u548c\u5b57\u7b26\u4e32\u5904\u7406\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p>*<em>1. \u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528while(<em>a  ==<em>b  )\u8fd9\u6837\u7684\u8bed\u53e5\uff1f<\/em><\/em><br \/>\n\u8fd9\u6837\u7684\u8bed\u53e5\u901a\u5e38\u7528\u4e8e\u5faa\u73af\u4e2d\u7684\u6761\u4ef6\u5224\u65ad\uff0c\u5f53<\/em>a\u548c*b\u7684\u503c\u76f8\u7b49\u65f6\uff0c\u5faa\u73af\u4f1a\u7ee7\u7eed\u6267\u884c\u4e0b\u53bb\u3002\u8fd9\u79cd\u6761\u4ef6\u5224\u65ad\u53ef\u4ee5\u7528\u6765\u5b9e\u73b0\u67d0\u79cd\u7279\u5b9a\u7684\u903b\u8f91\u6216\u8005\u63a7\u5236\u6d41\u7a0b\uff0c\u901a\u5e38\u5728\u9700\u8981\u8fed\u4ee3\u6bd4\u8f83\u4e24\u4e2a\u5143\u7d20\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u3002<\/p>\n<p>*<em>2. \u5728C\u8bed\u8a00\u4e2d\uff0c\u5982\u4f55\u7406\u89e3while(<em>a  ==<em>b  )\uff1f<\/em><\/em><br \/>\n\u8fd9\u662f\u4e00\u79cd\u6307\u9488\u6bd4\u8f83\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u5224\u65ad\u6307\u9488<\/em>a\u548c\u6307\u9488*b\u6240\u6307\u5411\u7684\u5185\u5b58\u5355\u5143\u4e2d\u7684\u503c\u662f\u5426\u76f8\u7b49\u6765\u786e\u5b9a\u5faa\u73af\u662f\u5426\u7ee7\u7eed\u6267\u884c\u3002\u8fd9\u79cd\u6bd4\u8f83\u901a\u5e38\u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u6307\u9488\u6307\u5411\u7684\u5185\u5bb9\u662f\u5426\u76f8\u7b49\uff0c\u4f8b\u5982\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u540c\u3002<\/p>\n<p>*<em>3. \u5982\u4f55\u4f7f\u7528while(<em>a  ==<em>b  )\u8fdb\u884c\u5b57\u7b26\u4e32\u6bd4\u8f83\uff1f<\/em><\/em><br \/>\n\u53ef\u4ee5\u6839\u636e\u6307\u9488<\/em>a\u548c\u6307\u9488*b\u6240\u6307\u5411\u7684\u5b57\u7b26\u7684\u503c\u662f\u5426\u76f8\u7b49\u6765\u5224\u65ad\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u540c\u3002\u6bd4\u8f83\u7684\u8fc7\u7a0b\u901a\u5e38\u4f7f\u7528\u5faa\u73af\u6765\u904d\u5386\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\uff0c\u5e76\u4e14\u5728\u5faa\u73af\u7684\u6bcf\u4e00\u6b21\u8fed\u4ee3\u4e2d\u5224\u65ad\u5f53\u524d\u5b57\u7b26\u662f\u5426\u76f8\u7b49\u3002\u5982\u679c\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u6240\u6709\u5b57\u7b26\u90fd\u76f8\u7b49\uff0c\u90a3\u4e48\u5faa\u73af\u5c06\u4e00\u76f4\u6267\u884c\u4e0b\u53bb\uff0c\u76f4\u5230\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u76f8\u7b49\u6216\u8005\u904d\u5386\u7ed3\u675f\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5b57\u7b26\u4e32\u7684\u6bd4\u8f83\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728C\u8bed\u8a00\u4e2d\uff0cwhile(*a == *b)\u8868\u793a\u5728while\u5faa\u73af\u6761\u4ef6\u4e0b\uff0c\u53ea\u8981\u6307\u9488a\u6240\u6307\u5411\u4f4d\u7f6e\u7684\u503c\u4e0e\u6307\u9488b\u6240\u6307\u5411\u4f4d [&hellip;]","protected":false},"author":3,"featured_media":297038,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/296995"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=296995"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/296995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/297038"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=296995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=296995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=296995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}