{"id":595,"date":"2023-02-23T17:28:16","date_gmt":"2023-02-23T09:28:16","guid":{"rendered":"http:\/\/72.44.76.42\/?p=595"},"modified":"2023-05-29T13:33:47","modified_gmt":"2023-05-29T05:33:47","slug":"c%e8%af%ad%e8%a8%80%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"https:\/\/www.notown.top\/?p=595","title":{"rendered":"C\u8bed\u8a00\u6307\u9488"},"content":{"rendered":"<div>\n<h2>\u4e8c\u7ef4\u6570\u7ec4\u548c\u6307\u9488<\/h2>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>int a&#91;3]&#91;4] = { {1,3,5,7},{9,11,13,15},{17,19,21,23} }; \/\/ \u8bbe\u8be5\u6570\u7ec4\u7684\u5730\u5740\u4e3a2000<\/code><\/pre>\n\n\n\n<p>a\u662f\u4e8c\u7ef4\u6570\u7ec4\u540d\uff0ca\u6570\u7ec4\u67093\u4e2a\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u56e0\u6b64\u53c8\u79f0a\u6570\u7ec4\u67093\u4e2a\u884c\u5143\u7d20\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6bcf\u4e2a\u884c\u5143\u7d20\u662f\u4e00\u4f4d\u6570\u7ec4\uff0c\u5305\u542b4\u4e2a\u5143\u7d20\uff08\u53c8\u79f0\u5217\u5143\u7d20\uff09<\/li><li>a+0\u662f\u7b2c0\u884c\u7684\u5730\u5740\uff0ca+1\u662f\u7b2c1\u884c\u5730\u5740\uff0c\u90a3\u4e48a+1\u5c31\u7b49\u4e8e2000+16 = 2016<\/li><li>a[0],a[1]\u662f\u4e00\u7ef4\u6570\u7ec4\u540d\uff0c\u7b49\u540c\u4e8e\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u9996\u5730\u5740\uff0c\u5373&amp;a[0][0],&amp;a[1][0]\uff0c\u53c8a[0],a[1]\u8fd8\u53ef\u4ee5\u7528*(a+0), *(a+1)\u8868\u793a<\/li><li><strong>\u5355\u4ece\u503c\u6765\u770b<\/strong>\uff0ca+1\u662f\u7b49\u4e8e*(a+1)\uff0c\u540c\u65f6\u4ed6\u4e24\u4e5f\u90fd\u662f\u5730\u5740\uff0c\u4f46a+1\u662f\u6307\u5411\u7b2c\u4e00\u884c\u7684\u5730\u5740\uff0c*(a+1)\u662f\u7b2c\u4e00\u884c\u6240\u5728\u4e00\u7ef4\u6570\u7ec4\u7684\u6574\u578b\u53d8\u91cf\u7684\u5730\u5740\uff0c\u5c31\u662f\u8bf4\u6307\u9488\u7c7b\u578b\u4e0d\u4e00\u6837\uff0c\u56e0\u6b64a+1+1\u5c31\u662f2032, *(a+1) + 1\u5219\u662f2020<\/li><li>\u56e0\u6b64\u8981\u7528\u4e00\u4e2a\u6307\u9488\u6307\u5411\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u90a3\u4e48\u5b9a\u4e49int (*pt)[4];\uff0c\u6b64\u65f6pt\u5c31\u53ef\u8fdb\u884c\u8d4b\u503cpt = a[0];<\/li><li>a\u548ca+1\u662f\u6307\u5411\u884c\u7684\u6307\u9488\uff0c\u5728\u4ed6\u4eec\u524d\u9762\u52a0*\uff0c\u53d8\u6210*a\u548c*(a+1)\u540e\u5c31\u53d8\u6210\u4e86\u5217\u6307\u9488\uff0c\u5373`*a + i`\u5c31\u53ef\u9009\u4e2da\u5217\uff0c\u800c\u5217\u6307\u9488\u524d\u9762\u52a0&amp;\u80fd\u53d8\u56de\u884c\u6307\u9488\uff0c\u5982&amp;a[1]<\/li><li><strong>\u4e0d\u8981<\/strong>\u628a&amp;a[i]\u7b80\u5355\u7406\u89e3\u4e3aa[i]\u5143\u7d20\u7684\u5b58\u50a8\u5355\u5143\u7684\u5730\u5740\uff0c\u56e0\u4e3a\u4e0d\u5b58\u5728a[i]\u8fd9\u6837\u4e00\u4e2a\u5b9e\u9645\u7684\u6570\u636e\u5b58\u50a8\u5355\u5143\uff0c\u4ed6\u53ea\u662f\u4e00\u79cd\u5730\u5740\u7684\u8ba1\u7b97\u65b9\u6cd5\u3002\u800c\u5728\u4e00\u7ef4\u6570\u7ec4b\u4e2d\uff0cb+i\u6240\u6307\u7684\u662f\u4e00\u4e2a\u5b9e\u9645\u6570\u7ec4\u5143\u7d20\u7684\u5b58\u50a8\u5355\u5143<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\u8868\u8fbe\u5f0f<\/td><td>\u503c<\/td><td>\u57fa\u7c7b\u578b<\/td><\/tr><tr><td>a+i<\/td><td>2000 + 16 *i<\/td><td>\u4e00\u7ef4\u6570\u7ec4<\/td><\/tr><tr><td>a[i]<\/td><td>2000 + 16 *i<\/td><td>int<\/td><\/tr><tr><td>*(a+i)<\/td><td>2000 + 16 *i<\/td><td>int<\/td><\/tr><tr><td>&amp;a[i]<\/td><td>2000 + 16 *i<\/td><td>\u4e00\u7ef4\u6570\u7ec4<\/td><\/tr><tr><td>&amp;a[i][0]<\/td><td>2000 + 16 *i<\/td><td>int<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u7528\u8fd9\u79cd\u65b9\u5f0f\u5b9a\u4e49\u7684\u6570\u7ec4\u5728\u5185\u5b58\u4e2d\u5176\u5b9e\u5c31\u662f\u6309\u884c\u4f18\u5148\u5b58\u653e\uff0c\u5373\u7528\u8fde\u7eed\u768412\u4e2a\u6574\u578bint\u7684\u7a7a\u95f4\u5b58\u653e\u8be5\u6570\u7ec4\uff0c\u56e0\u6b64\u8ba1\u7b97a[i][j]\u7684\u76f8\u5bf9\u4f4d\u7f6e\u6240\u7528\u7684\u516c\u5f0f\u4e3ai*4 + j<\/p>\n\n\n\n<p>\u7528\u8fd9\u79cd\u65b9\u5f0f\u5b9a\u4e49\u6570\u7ec4\u65f6\uff0c\u82e5\u60f3\u628a\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570\u653e\u5728\u53e6\u4e00\u4e2a\u51fd\u6570\u4e2d\u5904\u7406\uff0c\u6709\u4e24\u4e2a\u65b9\u6cd5<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f20\u8fd9\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2aint\u5143\u7d20\u7684\u5730\u5740p\u548c\u957f\u5ea6n\uff0c\u7136\u540e\u901a\u8fc7*(p+i)\u8bbf\u95ee<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>void visit(int *p, int n){\n    for(int i = 0; i &lt; n; ++i)\n        printf(\"%d\", *(p+i)) }\nvisit(a&#91;0], 12);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f20\u8fd9\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u7684\u9996\u884c\u5730\u5740\uff0c\u7136\u540e\u4f20\u884c\u6570\u5217\u6570<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>void visit(int (*p)&#91;4], int m, int n){\n    for(int i = 0; i &lt; m; ++i){\n        for(int j = 0; j &lt; n; ++j){\n            printf(\"%d \", *(*(p+i)+ j) );\n        } \n    }\n}\nvisit(a, 3, 4);<\/code><\/pre>\n\n\n\n<p>\u8fd8\u6709\u53e6\u4e00\u79cd\u5b9a\u4e49\u4e8c\u7ef4\u6570\u7ec4\u7684\u65b9\u6cd5\uff0c\u5373\u52a8\u6001\u5206\u914d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int m = 3, n = 4;\nint **a = (int**)malloc( sizof(int*) * m);\/\/\u5148\u628aa\u5b9a\u4e49\u6210\u6307\u9488\u7684\u6307\u9488\uff0ca\u6307\u5411\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u5730\u5740\uff0c\u5176\u4e2d\u8fd9\u4e2a\u4e00\u7ef4\u6570\u7ec4\u662f\u88c5m\u4e2aint\u7c7b\u578b\u7684\u6307\u9488\nfor(int i = 0; i &lt; m; ++i) {\n    a&#91;i] = (int*)malloc(sizeof(int) * n);\/\/\u6bcf\u4e2aint\u7c7b\u578b\u6307\u9488\u90fd\u6307\u5411\u5404\u79cd\u7684\u4e00\u7ef4\u6570\u7ec4\uff0c\u8be5\u4e00\u7ef4\u6570\u7ec4\u662f\u88c5n\u4e2aint\u7c7b\u578b\n    for(int j = 0; j &lt; n; ++j) a&#91;i]&#91;j] = 0;\/\/\u521d\u59cb\u5316\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u79cd\u52a8\u6001\u5206\u914d\u7684\u65b9\u6cd5\u5728\u5185\u5b58\u4e0a\uff0c\u4e0e\u4e0a\u9762int a[3][4]\u4e0d\u540c\uff0c\u8fd9\u79cd\u65b9\u6cd5\u540c\u4e00\u884c\u5185\u7684\u5143\u7d20\u8fde\u7eed\uff0c\u4f46\u4e0d\u540c\u884c\u4e4b\u95f4\u5730\u5740\u968f\u673a<\/p>\n\n\n<h2 id=\"%E5%AD%97%E7%AC%A6%E6%8C%87%E9%92%88%E5%8F%98%E9%87%8F%E5%92%8C%E5%AD%97%E7%AC%A6%E6%95%B0%E7%BB%84\" class=\"code-line\" dir=\"auto\" data-line=\"39\">\u5b57\u7b26\u6307\u9488\u53d8\u91cf\u548c\u5b57\u7b26\u6570\u7ec4<\/h2>\n\n\n<p>\u7528\u5b57\u7b26\u6570\u7ec4\u548c\u5b57\u7b26\u6307\u9488\u53d8\u91cf\u90fd\u80fd\u5b9e\u73b0\u5b57\u7b26\u4e32\u7684\u5b58\u50a8\u548c\u8fd0\u7b97\uff0c\u4f46\u4ed6\u4eec\u4e8c\u8005\u6709\u533a\u522b<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b57\u7b26\u6570\u7ec4\u540d\u662f\u4e2a\u5e38\u91cf\uff0c\u5b83\u53ea\u8868\u793a\u8be5\u5b57\u7b26\u6570\u7ec4\u7684\u8d77\u59cb\u5730\u5740\uff0c\u4e0d\u53ef\u88ab\u8d4b\u503c\uff0c\u5b57\u7b26\u6307\u9488\u53d8\u91cf\u4e5f\u8868\u793a\u67d0\u4e2a\u5b57\u7b26\u7684\u5730\u5740\uff0c\u4f46\u4ed6\u672c\u8d28\u4e0a\u8fd8\u662f\u4e2a\u6307\u9488\u53d8\u91cf\uff0c\u53ef\u4ee5\u8d4b\u503c<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>char *a;\na = \"hello world!\";\/\/\u6b63\u786e\nchar str&#91;14];\nstr&#91;0] = 'h';\/\/ \u6b63\u786e\uff0c\u53ef\u4ee5\u4fee\u6539\u6570\u7ec4\u5185\u7684\u67d0\u4e2a\u5143\u7d20\nstr = \"hello world!\";\/\/ \u9519\u8bef\uff0cstr\u662f\u6570\u7ec4\u540d\uff0c\u662f\u5e38\u91cf\u5730\u5740\uff0c\u4e0d\u80fd\u88ab\u8d4b\u503c\nchar str&#91;14] = \"hello world!\";\/\/ \u8981\u4e48\u5c31\u4e00\u5f00\u59cb\u7684\u65f6\u5019\u5c31\u521d\u59cb\u5316<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b57\u7b26\u6570\u7ec4\u4e2d\u5404\u5143\u7d20\u7684\u503c\u662f\u53ef\u4ee5\u6539\u53d8\u7684\uff08\u53ef\u518d\u8d4b\u503c\uff09\uff0c\u4f46\u5b57\u7b26\u6307\u9488\u53d8\u91cf\u6307\u5411\u7684\u5b57\u7b26\u4e32\u5e38\u91cf\u4e2d\u7684\u5185\u5bb9\u662f\u4e0d\u53ef\u4ee5\u518d\u8d4b\u503c<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>char a&#91;] = \"house\";\/\/ a\u6570\u7ec4\u521d\u59cb\u5316\uff0c\u6bcf\u4e2a\u5b58\u50a8\u5355\u5143\u5b58\u4e00\u4e2a\u5b57\u7b26\nchar *b = \"house\";\/\/ b\u6307\u9488\u6307\u5411\u5b57\u7b26\u4e32\u5e38\u91cf\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\na&#91;2] = 't';\/\/\u6b63\u786e\uff0c\u53ef\u6b63\u5e38\u4fee\u6539\nb&#91;2] = 't';\/\/\u975e\u6cd5\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u4e0d\u80fd\u6539\u53d8<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u51fd\u6570\u6307\u9488<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5982\u679c\u5728\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u5728\u7f16\u8bd1\u65f6\u4f1a\u628a\u51fd\u6570\u7684\u6e90\u4ee3\u7801\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u4ee3\u7801\u5e76\u5206\u914d\u4e00\u6bb5\u5b58\u50a8\u7a7a\u95f4\uff0c\u8fd9\u6bb5\u5185\u5b58\u7a7a\u95f4\u6709\u4e00\u4e2a\u8d77\u59cb\u5730\u5740\uff0c\u4e5f\u79f0\u4e3a\u51fd\u6570\u5165\u53e3\u5730\u5740\u3002\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\u90fd\u4ece\u8be5\u5730\u5740\u5165\u53e3\u5f00\u59cb\u6267\u884c\u6b64\u6bb5\u51fd\u6570\u4ee3\u7801\u3002\u51fd\u6570\u540d\u5c31\u662f\u51fd\u6570\u7684\u6307\u9488\uff0c\u4ee3\u8868\u51fd\u6570\u7684\u8d77\u59cb\u5730\u5740\u3002&nbsp;<code>int (* p)(int, int)<\/code>&nbsp;\u4e0a\u8ff0\u8bed\u53e5\u5373\u5b9a\u4e49p\u662f\u4e00\u4e2a\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\u53d8\u91cf\uff0c\u5b83\u6307\u5411\u7684\u51fd\u6570\u7c7b\u578b\u4e3a\uff1a\u8fd4\u56de\u7c7b\u578b\u4e3aint\u7684\uff0c\u6709\u4e24\u4e2aint\u578b\u53c2\u6570\u7684\u51fd\u6570\uff0c\u8be5\u7c7b\u578b\u53ef\u7528int (*)(int, int)\u8868\u793a<\/p><cite>\u2014\u2014C\u7a0b\u5e8f\u8bbe\u8ba1\u7b2c\u4e94\u7248<\/cite><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>\u89e3\u8bfb\uff1ap\u5148\u4e0e *\u7ed3\u5408\uff0c\u8868\u660ep\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u7136\u540e\u540e\u9762\u7684()\u8868\u9762\u4ed6\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff1b\u82e5\u6f0f\u6389 *p\u4e24\u8fb9\u7684\u62ec\u53f7\uff0c\u5219p\u4f1a\u5148\u548c()\u7ed3\u5408\uff0c\u8868\u660ep\u662f\u4e00\u4e2a\u6709\u4e24\u4e2aint\u53c2\u6570\u7684\u51fd\u6570\uff0c\u5e76\u4e14\u8be5\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\u6307\u9488<\/li><li>\u7528\u6cd5\uff1a int result  = ( *p)(\u53c2\u65701, \u53c2\u65702);\uff0c\u4e5f\u76f8\u5f53\u4e8eint result = p(\u53c2\u65701, \u53c2\u65702);<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>int myMax(int a, int b){\n    if (a &gt;= b) return a;\n    return b;\n}\nint res01 = myMax(1,2);\nint (*p)(int,int) = myMax;\nint res02 = (* p)(1,2);\nprintf(\"res01=%d,res02=%d\\n\", res01, res02);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>NOTE: \u51fd\u6570\u6307\u9488\u4e0d\u80fd\u8fdb\u884c\u7b97\u672f\u8fd0\u7b97<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u6307\u9488\u6570\u7ec4<\/h2>\n\n\n\n<p>\u6307\u9488\u6570\u7ec4\uff1a\u5176\u5143\u7d20\u5747\u4e3a\u6307\u9488\u7c7b\u578b&nbsp;<code>int * p[4];<\/code>&nbsp;\u89e3\u8bfb\uff1ap\u5148\u4e0e[4]\u7ed3\u5408\uff0c\u8868\u660ep\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u7136\u540eint *\u6307\u660e\u4e86\u5b83\u662f\u4e00\u4e2a\u5143\u7d20\u7c7b\u578b\u4e3a\u6574\u578b\u6307\u9488\u7684\u6570\u7ec4 \u6613\u6df7\uff1a<code>int (* p)[4]<\/code>\u8868\u660ep\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5b83\u6307\u5411\u6709\u56db\u4e2a\u5143\u7d20\u7684\u4e00\u7ef4\u6570\u7ec4<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e8c\u7ef4\u6570\u7ec4\u548c\u6307\u9488 a\u662f\u4e8c\u7ef4\u6570\u7ec4\u540d\uff0ca\u6570\u7ec4\u67093\u4e2a\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u56e0\u6b64\u53c8\u79f0a\u6570\u7ec4\u67093\u4e2a\u884c\u5143\u7d20\u3002 \u6bcf\u4e2a&hellip;<a href=\"https:\/\/www.notown.top\/?p=595\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">C\u8bed\u8a00\u6307\u9488<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[11],"tags":[],"class_list":["post-595","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/www.notown.top\/index.php?rest_route=\/wp\/v2\/posts\/595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.notown.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.notown.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.notown.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.notown.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=595"}],"version-history":[{"count":5,"href":"https:\/\/www.notown.top\/index.php?rest_route=\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":637,"href":"https:\/\/www.notown.top\/index.php?rest_route=\/wp\/v2\/posts\/595\/revisions\/637"}],"wp:attachment":[{"href":"https:\/\/www.notown.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.notown.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.notown.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}