{"id":2554,"date":"2011-02-10T01:48:39","date_gmt":"2011-02-09T17:48:39","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=2554"},"modified":"2011-03-02T09:19:27","modified_gmt":"2011-03-02T01:19:27","slug":"%e5%a4%9a%e7%bb%b4%e6%95%b0%e7%bb%84%e9%82%a3%e5%9b%9e%e4%ba%8b%e5%84%bf","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/2554","title":{"rendered":"\u591a\u7ef4\u6570\u7ec4\u90a3\u56de\u4e8b\u513f"},"content":{"rendered":"<p>\u524d\u9762\u51e0\u7bc7\u201c\u90a3\u56de\u4e8b\u513f\u201d\u7684\u6587\u7ae0\u66f4\u5f3a\u8c03\u4e00\u7ef4\u7ec4\u548c\u6307\u9488\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u672c\u6587\u5173\u6ce8\u7684\u662f\u591a\u7ef4\u6570\u7ec4\uff0c\u5373\u201c\u6570\u7ec4\u7684\u6570\u7ec4\u201d\u3002<\/p>\n<h3>\u591a\u7ef4\u6570\u7ec4<\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u591a\u7ef4\u6570\u7ec4\u62bd\u8c61\u7684\u770b\u4f5c\u662f\u5177\u6709\u67d0\u79cd\u7c7b\u578b\u7684\u4e00\u7ef4\u6570\u7ec4\u3002\u5f53\u201c\u67d0\u79cd\u7c7b\u578b\u201d\u4e3a\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\u65f6\uff0c\u591a\u7ef4\u6570\u7ec4\u5c31\u9000\u5316\u6210\u666e\u901a\u7684\u4e00\u7ef4\u6570\u7ec4\uff1b\u5f53\u201c\u67d0\u79cd\u7c7b\u578b\u201d\u4ecd\u7136\u4e3a\u6570\u7ec4\u65f6\uff0c\u90a3\u4e48\u5c31\u5f62\u6210\u4e86\u591a\u7ef4\u6570\u7ec4\u3002\u4e5f\u5c31\u662f\u8bf4\u4efb\u4f55\u4e00\u4e2a\u591a\u7ef4\u6570\u7ec4\u90fd\u53ef\u4ee5\u5206\u89e3\u6210\u51e0\u4e2a\u4e00\u7ef4\u6570\u7ec4\u3002<\/p>\n<p>\u4e0b\u9762\u901a\u8fc7\u793a\u4f8b\u7a0b\u5e8f\u6765\u6df1\u5165\u4e86\u89e3\u591a\u7ef4\u6570\u7ec4ma[2][3]\u7684\u6784\u6210\u3002<\/p>\n<pre class=\"brush:c\">#include &lt; stdio.h &gt;\r\n\r\nint main()\r\n{\r\n\tint ma[2][3];\r\n\tint (*r)[2][3];\r\n\tint (*p)[3];\r\n\tint *t;\r\n\r\n\t\/*\u4ee3\u7801\u6bb51*\/\r\n\tp = ma;\r\n\tprintf(\"sizeof(ma[0])=%d\\n\",sizeof(ma[0]));\r\n\tprintf(\"ma      =%p\\tp   =%p\\n\",ma,p);\r\n\tprintf(\"p+1 =%p\\n\",p+1);\r\n\t\/*\u4ee3\u7801\u6bb52*\/\r\n\tr = &amp;ma;\r\n\tprintf(\"sizeof(ma)=%d\\n\",sizeof(ma));\r\n\tprintf(\"&amp;ma     =%p\\tr  =%p\\n\",&amp;ma,r);\r\n\tprintf(\"&amp;ma+1   =%p\\tr+1=%p\\n\",&amp;ma+1,r+1);\r\n\t\/*\u4ee3\u7801\u6bb53*\/\r\n\tt = ma[0];\r\n\tprintf(\"sizeof(ma[0][0])=%d\\n\",sizeof(ma[0][0]));\r\n\tprintf(\"ma[0]   =%p\\tt   =%p\\n\",ma[0],t);\r\n\tprintf(\"ma[0]+1 =%p\\tt+1 =%p\\n\",ma[0]+1,t+1);\r\n\treturn 0;\r\n}<\/pre>\n<p>\u7531\u591a\u7ef4\u6570\u7ec4ma\u6700\u5de6\u7ef4\u7684\u957f\u5ea62\u53ef\u77e5\uff0cma\u6570\u7ec4\u5305\u542b\u4e24\u4e2a\u5143\u7d20ma[0]\u548cma[1]\u3002\u6570\u7ec4\u540dma\u5728\u8868\u8fbe\u5f0f\u4e2d\u662f\u6570\u7ec4ma\u9996\u5143\u7d20\u7684\u9996\u5730\u5740\u3002\u5728\u4ee3\u7801\u6bb51\u4e2d\u5c06ma\u8d4b\u503c\u7ed9\u6570\u7ec4\u6307\u9488p\uff0c\u5219p\u6307\u5411\u591a\u7ef4\u6570\u7ec4ma\u7684\u9996\u5143\u7d20ma[0]\uff0c\u5219p+1\u6307\u5411\u7b2c\u4e8c\u4e2a\u5143\u7d20ma[1]\u3002\u5176\u4e2dp\u662f\u4e00\u4e2a\u6570\u7ec4\u6307\u9488\uff0c\u5b83\u6307\u5411\u4e00\u4e2a\u957f\u5ea6\u4e3a3\u7684\u6570\u7ec4\uff0c\u5219\u6307\u9488p\u6bcf\u6b21\u79fb\u52a8\u7684\u504f\u79fb\u91cf\u4e3a12\u3002\u53ef\u53c2\u8003\u4e0b\u56fe\uff1a<\/p>\n<p><a rel=\"attachment wp-att-2558\" href=\"http:\/\/edsionte.com\/techblog\/archives\/2554\/array1\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2558\" title=\"array1\" src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array1.jpg\" alt=\"\" width=\"410\" height=\"138\" srcset=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array1.jpg 410w, http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array1-300x100.jpg 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/a><br \/>\n\u5728\u4ee3\u78012\u4e2d\u5bf9ma\u53d6\u5730\u5740\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u6307\u9488r\u3002r\u73b0\u5728\u6307\u5411\u4e00\u4e2a\u201c\u7b2c\u4e00\u7ef4\u7684\u5927\u5c0f\u4e3a2\uff0c\u7b2c\u4e8c\u7ef4\u7684\u5927\u5c0f\u4e3a3\u7684\u6570\u7ec4\u201d\uff0c\u5219r+1\u5c06\u6307\u5411\u4e0b\u4e00\u4e2a\u8fd9\u6837\u7684\u6570\u7ec4\uff08\u5c3d\u7ba1\u8fd9\u6837\u7684\u6570\u7ec4\u5e76\u4e0d\u5b58\u5728\uff09\u3002\u7531\u6b64\u4e5f\u53ef\u5f97\u77e5r\u6bcf\u6b21\u7684\u504f\u79fb\u91cf\u4e3a24\u3002<\/p>\n<p><a rel=\"attachment wp-att-2559\" href=\"http:\/\/edsionte.com\/techblog\/archives\/2554\/array2\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2559\" title=\"array2\" src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array2.jpeg\" alt=\"\" width=\"495\" height=\"135\" srcset=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array2.jpeg 495w, http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array2-300x81.jpg 300w\" sizes=\"auto, (max-width: 495px) 100vw, 495px\" \/><\/a><br \/>\nma[0]\u548cma[1]\u90fd\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a3\u7684\u6574\u578b\u6570\u7ec4\uff0c\u73b0\u5728\u4ee5ma[0]\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\u3002ma[0]\u4e2d\u5305\u542b\u4e09\u4e2a\u5143\u7d20ma[0][0]\uff0cma[0][1]\u548cma[0][2]\u3002\u5728\u4ee3\u7801\u6bb53\u4e2d\u5c06ma[0]\u8d4b\u503c\u7ed9t\uff0c\u5219t\u6307\u5411\u6570\u7ec4ma[0]\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20a[0][0]\uff0c\u5219t+1\u548ct+2\u5219\u4f9d\u6b21\u6307\u5411\u7b2c\u4e8c\u4e2a\u5143\u7d20\u548c\u7b2c\u4e09\u4e2a\u5143\u7d20\u3002<\/p>\n<p><a rel=\"attachment wp-att-2560\" href=\"http:\/\/edsionte.com\/techblog\/archives\/2554\/array3\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2560\" title=\"array3\" src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array3.jpeg\" alt=\"\" width=\"409\" height=\"109\" srcset=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array3.jpeg 409w, http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2011\/02\/array3-300x79.jpg 300w\" sizes=\"auto, (max-width: 409px) 100vw, 409px\" \/><\/a><br \/>\n\u5bf9\u591a\u7ef4\u6570\u7ec4ma\u7684\u7ed3\u6784\u6709\u4e86\u4e00\u5b9a\u4e86\u89e3\u540e\uff0c\u73b0\u5728\u518d\u770b\u4e0a\u8ff0\u7a0b\u5e8f\u7684\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-laptop:~\/code\/expertC$ gcc array.c -o array\r\nedsionte@edsionte-laptop:~\/code\/expertC$ .\/array\r\nsizeof(ma[0])=12\r\nma   =0xbfdfaa6c\tp=0xbfdfaa6c\r\np+1  =0xbfdfaa78\r\nsizeof(ma)=24\r\n&amp;ma  =0xbfdfaa6c\tr=0xbfdfaa6c\r\nr+1  =0xbfdfaa84\r\nsizeof(ma[0][0])=4\r\nma[0]=0xbfdfaa6c\tt=0xbfdfaa6c\r\nt+1  =0xbfdfaa70<\/pre>\n<p>\u6ce8\u610f\u5728\u7ed3\u679c\u4e2d\uff0cp\uff0cr\u548ct\u7684\u503c\u5747\u76f8\u540c\uff0c\u4f46\u662f\u6240\u6307\u5411\u7684\u6570\u636e\u5374\u4e0d\u540c\u3002\u66f4\u5177\u4f53\u7684\u8bf4\uff0c\u8fd9\u4e09\u4e2a\u6307\u9488\u6bcf\u6b21\u79fb\u52a8\u65f6\u7684\u504f\u79fb\u91cf\u4e0d\u540c\u3002<\/p>\n<h3>\u591a\u7ef4\u6570\u7ec4\u7684\u521d\u59cb\u5316<\/h3>\n<p>\u6570\u7ec4\u7684\u521d\u59cb\u5316\u53ea\u80fd\u5728\u5bf9\u6570\u7ec4\u8fdb\u884c\u58f0\u660e\uff08\u5177\u4f53\u4e3a\u5b9a\u4e49\u578b\u58f0\u660e\uff09\u65f6\u8fdb\u884c\u3002\u4e00\u7ef4\u6570\u7ec4\u7684\u521d\u59cb\u5316\u5f88\u7b80\u5355\uff0c\u53ea\u8981\u5c06\u6240\u6709\u521d\u59cb\u503c\u653e\u5728\u4e00\u4e2a\u5927\u62ec\u53f7\u4e2d\u5373\u53ef\u3002\u5982\u679c\u58f0\u660e\u6570\u7ec4\u65f6\u672a\u6307\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u5219\u7f16\u8bd1\u5668\u4f1a\u6839\u636e\u521d\u59cb\u503c\u7684\u4e2a\u6570\u6765\u786e\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n<pre class=\"brush:c\">#include &lt; stdio.h &gt;\r\n\r\nint main()\r\n{\r\n\tint m[] = {1,2,3};\r\n\tint n[] = {1,2,3,};\r\n\r\n\tprintf(\"length(m)=%d\\n\",sizeof(m)\/sizeof(m[0]));\r\n\tprintf(\"length(n)=%d\\n\",sizeof(n)\/sizeof(n[0]));\r\n\treturn 0;\r\n}\r\n\r\n\/* \u7f16\u8bd1\u5e76\u8fd0\u884c *\/\r\nedsionte@edsionte-laptop:~\/code\/expertC$ gcc init_array.c -o init_array\r\nedsionte@edsionte-laptop:~\/code\/expertC$ .\/init_array\r\nlength(m)=3\r\nlength(n)=3<\/pre>\n<p>\u6ce8\u610f\uff0c\u5728\u6700\u540e\u4e00\u4e2a\u521d\u59cb\u503c\u540e\u9762\u53ef\u4ee5\u7ee7\u7eed\u52a0\u4e00\u4e2a\u9017\u53f7\u4e5f\u53ef\u4ee5\u7701\u7565\uff0c\u8fd9\u5e76\u4e0d\u5f71\u54cd\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n<p>\u5bf9\u4e8e\u591a\u7ef4\u6570\u7ec4\u800c\u8a00\uff0c\u901a\u5e38\u4f7f\u7528\u5d4c\u5957\u7684\u5927\u62ec\u53f7\u8fdb\u884c\u591a\u7ef4\u6570\u7ec4\u7684\u521d\u59cb\u5316\u3002\u7531\u4e8e\u591a\u7ef4\u7684\u6570\u7ec4\u5176\u5b9e\u662f\u6709\u82e5\u5e72\u4e2a\u4e00\u7ef4\u6570\u7ec4\u6784\u6210\u7684\uff0c\u5219\u6bcf\u4e2a\u5927\u62ec\u53f7\u90fd\u4ee3\u8868\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u3002\u5bf9\u4e8e\u591a\u7ef4\u6570\u7ec4\u800c\u8a00\u53ea\u80fd\u7701\u7565\u6700\u5de6\u8fb9 \u4e0b\u6807\u7684\u957f\u5ea6\u3002<\/p>\n<pre class=\"brush:c\">#include &lt; stdio.h &gt;\r\n\r\nint main()\r\n{\r\n\tint b[][3] = {1,2,1,1};\r\n\tint c[][3] = {{1,2,1},{1,2,3},};\r\n\r\n\tprintf(\"length(b)=%d\\n\",sizeof(b)\/sizeof(b[0]));\r\n\tprintf(\"length(c)=%d\\n\",sizeof(c)\/sizeof(c[0]));\r\n\treturn 0;\r\n}\r\n\r\n\/* \u7f16\u8bd1\u5e76\u8fd0\u884c *\/\r\nedsionte@edsionte-laptop:~\/code\/expertC$ gcc init_array.c -o init_array\r\nedsionte@edsionte-laptop:~\/code\/expertC$ .\/init_array\r\nlength(b)=2\r\nlength(c)=2<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u4e0d\u4f7f\u7528\u5927\u62ec\u53f7\u4e5f\u53ef\u4ee5\u5bf9\u591a\u7ef4\u6570\u7ec4\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u53ea\u4e0d\u8fc7\u4ee3\u7801\u53ef\u8bfb\u6027\u8f83\u5dee\u3002<\/p>\n<h3>\u5b83\u603b\u662f\u8ff7\u60d1\u4f60\uff01<\/h3>\n<p>\u4e00\u65e6\u6d89\u53ca\u5230\u591a\u7ef4\u6570\u7ec4\uff0c\u603b\u6709\u4e9b\u8ba9\u4f60\u8ff7\u60d1\u7684\u5730\u65b9\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">\tchar ma[2][3][2]={\r\n\t\t{{1,2},{2,3},{3,4}},\r\n\t\t{{3,5},{4,5},{3,3}}\r\n\t};\r\n\r\nsizeof(ma[0,1,1])=\uff1f<\/pre>\n<p>\u5bf9\u4e8e\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u6700\u540e\u7684\u8ff7\u60d1\u70b9\u90fd\u53ef\u80fd\u843d\u5728ma[0,1,1]\u4e0a\u3002\u96be\u9053\u591a\u7ef4\u6570\u7ec4\u53ef\u4ee5\u8fd9\u6837\u4f7f\u7528\u5417\uff1f\u5982\u679cma[0,1,1]\u548cma[0][1][1]\u7b49\u4ef7\uff0c\u90a3\u4e48sizeof(ma[0,1,1])\u7684\u503c\u5c31\u662f1\u3002\u5f88\u53ef\u60dc\u8fd9\u6837\u7684\u731c\u6d4b\u662f\u4e0d\u6b63\u786e\u7684\uff0c\u6b63\u786e\u7b54\u6848\u4e3a6\u3002\u518d\u6bd4\u5982\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"brush:c\">\t\tchar ma[3][2] = {\r\n\t\t(1,2),(3,4),(5,3)\r\n\t};\r\n\r\nma[0][0]=\uff1f<\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u662f\u4e3a\u6570\u7ec4ma\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u90a3\u4e48ma[0][0]\u7684\u503c\u662f\u591a\u5c11\uff1f\u6050\u6015\u5f88\u591a\u4eba\u90fd\u4f1a\u8ba4\u4e3a\u662f1\u3002\u4e0d\u8fc7\u6b63\u786e\u7b54\u6848\u662f2\u3002<\/p>\n<p>\u8fd9\u4e24\u4e2a\u95ee\u9898\u90fd\u6d89\u53ca\u5230\u4e86\u9017\u53f7\u8868\u8fbe\u5f0f\u3002\u5982\u679c\u4f60\u5bf9\u9017\u53f7\u8868\u8fbe\u5f0f\u6709\u57fa\u672c\u7684\u4e86\u89e3\uff0c\u90a3\u4e48\u4e5f\u5c31\u6ca1\u6709\u4e0a\u8ff0\u90a3\u79cd\u83ab\u540d\u5176\u5999\u7684\u8ff7\u60d1\u4e86\u3002\u6839\u636e\u9017\u53f7\u8868\u8fbe\u5f0f\u7684\u8fd0\u7b97\uff0c\u5bf9\u4e8e\u4e3e\u4f8b1\u4e2d\u7684ma[0,1,1]\u5b9e\u9645\u4e0a\u7b49\u4ef7\u4e8ema[1]\uff1b\u5bf9\u4e8e\u4e3e\u4f8b2\u4e2d\u7684\u521d\u59cb\u5316\u5176\u5b9e\u7b49\u4ef7\u4e3achar ma[3][2] = {2,4,3}\u3002<\/p>\n<p><strong>\u53c2\u8003\uff1a<\/strong><\/p>\n<p><strong>\u300aC\u4e13\u5bb6\u7f16\u7a0b\u300b \u4eba\u6c11\u90ae\u7535\u51fa\u7248\u793e\uff1b\uff08\u7f8e\uff09\u6797\u767b\uff08LinDen.P.V.D\uff09 \u8457\uff0c\u5f90\u6ce2 \u8bd1\uff1b<\/strong><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u9762\u51e0\u7bc7\u201c\u90a3\u56de\u4e8b\u513f\u201d\u7684\u6587\u7ae0\u66f4\u5f3a\u8c03\u4e00\u7ef4\u7ec4\u548c\u6307\u9488\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u672c\u6587\u5173\u6ce8\u7684\u662f\u591a\u7ef4\u6570\u7ec4\uff0c\u5373\u201c\u6570\u7ec4\u7684\u6570\u7ec4\u201d\u3002 \u591a\u7ef4\u6570\u7ec4 \u6211 [&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,198,165,166],"class_list":["post-2554","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-198","tag-165","tag-166"],"views":5258,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/2554","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=2554"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/2554\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=2554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=2554"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=2554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}