{"id":1912,"date":"2010-10-30T17:59:26","date_gmt":"2010-10-30T09:59:26","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=1912"},"modified":"2010-10-30T18:09:36","modified_gmt":"2010-10-30T10:09:36","slug":"%e6%8c%87%e5%90%91%e4%b8%80%e7%bb%b4%e6%95%b0%e7%bb%84%e7%9a%84%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/1912","title":{"rendered":"\u6307\u5411\u4e00\u7ef4\u6570\u7ec4\u7684\u6307\u9488"},"content":{"rendered":"<p>\u4eca\u5929\u5728\u770b\u5230typedef int (*int_arry)[10];\u8fd9\u6761\u8bed\u53e5\u65f6\uff0c\u56e0\u4e3a\u5bf9\u8fd9\u6837\u7684\u5b9a\u4e49\u4f7f\u7528\u8f83\u5c11\uff0c\u5c31\u60f3\u7740\u7f16\u5199\u4e00\u4e2atest.c\u6765\u8bd5\u8bd5\u770b\u3002\u4e0d\u8fc7\uff0c\u5f53\u6211\u7f16\u5199\u5b8c\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5\u7a0b\u5e8f\u65f6\uff0c\u5374\u53d1\u73b0\u6211\u5bf9\u6307\u5411\u4e00\u7ef4\u6570\u7ec4\u7684\u6307\u9488\u7684\u4f7f\u7528\u4e86\u89e3\u751a\u5c11\u3002<\/p>\n<p>\u8d77\u521d\uff0c\u6211\u7684\u7a0b\u5e8f\u662f\u8fd9\u6837\uff1a<\/p>\n<pre class=\"brush:c\">\r\n#include  < stdio.h >\r\ntypedef int (*int_array)[10];\r\nint main()\r\n{\r\n\r\n\tint a[10]={1,2,3,4,5};\r\n\tint_array i=&amp;a;\r\n\r\n\tprintf(\"%d=%d\\n\",i[4],a[4]);\r\n      return 0;\r\n}<\/pre>\n<p>\u7f16\u8bd1\u540e\uff0c\u63d0\u793a\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre class=\"brush:c\">test.c: In function \u2018main\u2019:\r\ntest.c:10: warning: format \u2018%d\u2019 expects type \u2018int\u2019, but argument 2 has type \u2018int *\u2019<\/pre>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0ci[4]\u662f\u4e00\u4e2aint*\u578b\u7684\u6307\u9488\u3002\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u9519\u8bef\uff1f\u65e2\u7136i\u662f\u4e00\u4e2a\u6307\u5411\u670910\u4e2a\u6574\u5f62\u5143\u7d20\u6570\u7ec4\u7684\u6307\u9488\u3002\u90a3\u4e48\u5c06i\u6307\u5411\u6570\u7ec4a\uff0c\u7136\u540e\u4f7f\u7528i[4]\u83b7\u53d6\u7b2c\u56db\u4e2a\u5143\u7d20\u6709\u4ec0\u4e48\u9519\uff1f<\/p>\n<p>\u90a3\u6211\u4eec\u4ece\u53e6\u4e00\u4e2a\u89d2\u5ea6\u6765\u5206\u6790\uff0c\u4e00\u822ci[4]\u8fd9\u6837\u7684\u5f62\u5f0f\u90fd\u53ef\u4ee5\u770b\u6210*(i+4)\u8fd9\u6837\u7684\u5f62\u5f0f\u3002i+4\u662f\u4ec0\u4e48\uff1f\u5bf9\u4e86\uff01i\u662f\u4e00\u4e2a\u6570\u7ec4\u6307\u9488\uff0c\u90a3\u4e48i+4\u4e5f\u5c31\u662f\u4e00\u4e2a\u6570\u7ec4\u6307\u9488\u3002\u5982\u679c\u5c06i\u6240\u6307\u7684\u6570\u7ec4\u770b\u4f5c\u4e00\u4e2a\u4e8c\u7ef4\u8868\u7684\u7b2c1\u884c\uff0c\u90a3\u4e48i+4\u5c31\u662f\u6307\u5411\u7b2c5\u884c\u7684\u6307\u9488\u3002\u4e5f\u5c31\u662f\u8bf4\u5b83\u76f8\u5bf9\u4e8ei\u6240\u6307\u5411\u4f4d\u7f6e\u7684\u504f\u79fb\u91cf\u4e3a4*sizeof(int)*10\u4e2a\u5b57\u8282\u3002\u56e0\u6b64*(i+4)\u4ecd\u7136\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u53ea\u4e0d\u8fc7\u5b83\u6307\u5411\u7b2c5\u884c\u7684\u9996\u4e2a\u5143\u7d20\u3002<\/p>\n<p>\u770b\u6765\u6211\u4eec\u627e\u5230\u95ee\u9898\u6240\u5728\uff0ci[4]\u5e76\u4e0d\u662f\u4e00\u4e2a\u6574\u5f62\u5143\u7d20\uff0c\u800c\u662f\u4e00\u4e2a\u6307\u5411\u6574\u5f62\u5143\u7d20\u7684\u6307\u9488\u3002\u4e0a\u9762\u7a0b\u5e8f\u4e2d\uff0c\u6211\u539f\u672c\u7684\u610f\u601d\u662f\u901a\u8fc7i\u6765\u6253\u5370\u6570\u7ec4a\u4e2d\u7b2c\u56db\u4e2a\u5143\u7d20\u3002\u90a3\u4e48\u6b64\u523b\u6211\u4eec\u5e94\u8be5\u8fd9\u4e48\u4fee\u6539\uff1a<\/p>\n<pre class=\"brush:c\">printf(\"%d=%d\\n\",i[0][4],a[4]);<\/pre>\n<p>\u6216\u8005\u4e0b\u9762\u4efb\u610f\u4e00\u53e5\uff1a<\/p>\n<pre class=\"brush:c\">printf(\"%d=%d\\n\",(*(i+0))[4],a[4]);\r\nprintf(\"%d=%d\\n\",*(i[0]+4),a[4]);\r\nprintf(\"%d=%d\\n\",*(*(i+0)+4),a[4]);<\/pre>\n<p>\u4f60\u4f1a\u53d1\u73b0\uff0c\u5982\u679cp\u662f\u4e00\u4e2a\u6307\u5411\u6307\u9488\u7684\u6307\u9488\uff0c\u90a3\u4e48\u603b\u80fd\u591f\u901a\u8fc7\u4e24\u6b21\u7684*\u3001\u4e24\u6b21\u7684[]\u6216\u8005\u4e00\u6b21*\u548c\u4e00\u6b21[]\u53d6\u5f97\u8fd9\u4e2a\u6307\u9488\u6700\u7ec8\u6307\u5411\u7684\u6570\u636e\uff0c\u56e0\u4e3a\u8bf4\u5230\u5e95[]\u603b\u80fd\u591f\u5316\u6210*\u7684\u5f62\u5f0f\u3002\u7406\u89e3\u4e86\u8fd9\u4e9b\uff0c\u4e0a\u9762\u7684\u8bed\u53e5\u5bf9\u4f60\u4e5f\u5c31\u4e0d\u6210\u95ee\u9898\u4e86\u3002got it\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u5728\u770b\u5230typedef int (*int_arry)[10];\u8fd9\u6761\u8bed\u53e5\u65f6\uff0c\u56e0\u4e3a\u5bf9\u8fd9\u6837\u7684\u5b9a\u4e49\u4f7f\u7528\u8f83\u5c11\uff0c\u5c31\u60f3\u7740 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[109,165],"class_list":["post-1912","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-165"],"views":7853,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=1912"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1912\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=1912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=1912"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=1912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}