{"id":3141,"date":"2011-06-16T21:33:01","date_gmt":"2011-06-16T13:33:01","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3141"},"modified":"2011-07-08T09:49:32","modified_gmt":"2011-07-08T01:49:32","slug":"%e8%a5%bf%e9%82%aelinux%e5%85%b4%e8%b6%a3%e5%b0%8f%e7%bb%84%e7%ba%b3%e6%96%b0%e7%ac%94%e8%af%95%e8%af%95%e9%a2%98","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3141","title":{"rendered":"\u897f\u90aeLinux\u5174\u8da3\u5c0f\u7ec4\u7eb3\u65b0\u7b14\u8bd5\u8bd5\u9898"},"content":{"rendered":"<p>\u4e0b\u9762\u662f\u897f\u90aeLinux\u5c0f\u7ec4\u4eca\u5e74\u7eb3\u65b0\u7684\u7b14\u8bd5\u8bd5\u9898\uff0c\u539f\u6587\u5728<a href=\"http:\/\/www.xiyoulinux.org\/blog\/?p=221\" target=\"_blank\">\u8fd9\u91cc<\/a>\u3002<\/p>\n<p>1\u3001 \u4e0b\u9762\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f<br \/>\nint main()<br \/>\n{ int a = \uff081, 2\uff09;<br \/>\nprintf(\u201ca = %d\\n\u201d, a);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><br \/>\n<strong> a = 2<\/strong><br \/>\n<strong> \u8fd9\u91cc\u5229\u7528\u4e86\u9017\u53f7\u8868\u8fbe\u5f0f\u3002<\/strong><\/p>\n<p>2\u3001\u4e0b\u9762\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f<br \/>\nstruct value {<br \/>\nchar a[3];<br \/>\nshort b;<br \/>\n};<br \/>\nstruct value tmp;<br \/>\nprintf(\u201csizeof(tmp) is %d\\n\u201d, sizeof(tmp));<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><br \/>\n<strong> sizeof(tmp) is 6<\/strong><br \/>\n<strong> \u8fd9\u91cc\u6d89\u53ca\u5230\u5b57\u8282\u5bf9\u9f50\uff0ca\u6570\u7ec4\u540e\u586b\u5145\u4e861\u5b57\u8282\u3002<\/strong><\/p>\n<p>3\u3001\u7f16\u5199\u7a0b\u5e8f\u4ea4\u6362a\uff0cb\u7684\u503c\u3002\uff08\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff09<\/p>\n<p>4\u3001\u8bf4\u660e int *p[5] \u548c int (*p)[5] \u7684\u533a\u522b\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a\u524d\u8005\u662f\u4e00\u4e2a\u6307\u9488\u6570\u7ec4\uff0c\u540e\u8005\u662f\u4e00\u4e2a\u6570\u7ec4\u6307\u9488\u3002<\/strong><\/p>\n<p>5\u3001\u7f16\u5199\u51fd\u6570\uff0c\u5b9e\u73b0\u94fe\u8868\u7684\u521b\u5efa\uff0c\u8282\u70b9\u7684\u63d2\u5165\u548c\u5220\u9664\u3002<\/p>\n<p>6\u3001\u4e0b\u9762\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f<br \/>\nvoid f(int *p);<br \/>\nint main(void)<br \/>\n{<br \/>\nint *p;<br \/>\nf(p);<br \/>\nprintf(\u201c*p = %d\\n\u201d, *p);<br \/>\nreturn 0;<br \/>\n}<br \/>\nvoid f(int *p)<br \/>\n{<br \/>\nstatic int dummy = 5;<br \/>\np = &amp;dummy;<br \/>\n}<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><br \/>\n<strong> *p\u4e2d\u7684\u503c\u4e0d\u786e\u5b9a\u3002<\/strong><br \/>\n<strong> \u5927\u591a\u6570\u4eba\uff08\u5305\u62ec\u6211\uff09\u90fd\u4f1a\u8ba4\u4e3a*p\u7684\u503c\u662f5\uff0c\u4f46\u8fd9\u5e76\u4e0d\u6b63\u786e\u3002\u56e0\u4e3af\u51fd\u6570\u4f20\u9012\u7684\u662f\u6307\u9488\u53d8\u91cf\uff0c\u65e2\u7136\u662f\u53d8\u91cf\uff0c\u90a3\u4e48\u53ea\u80fd\u901a\u8fc7\u4f20\u9012\u5730\u5740\u6765\u786e\u4fdd\u5c06f\u4e2d\u7684\u503c\u996d\u6216\u5230\u4e3b\u51fd\u6570\u3002\u5982\u679cf\u4f20\u9012\u7684\u662f&amp;p\uff0c\u90a3\u4e48\u6700\u540e\u7684\u7ed3\u679c\u5e94\u8be5\u662f5\u3002<\/strong><\/p>\n<p>7\u3001\u8bf4\u660e\u5982\u4e0b\u4e24\u6bb5\u4ee3\u7801\u7684\u533a\u522b\u3002<br \/>\nchar * p = \u201cxiyou linux\u201d;<br \/>\nchar p[] = \u201cxiyou linux\u201d;<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><br \/>\n<strong> \u524d\u8005p\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u5b83\u6307\u5411\u4e00\u6bb5\u53ea\u8bfb\u5b57\u7b26\u4e32\u3002<\/strong><br \/>\n<strong> \u540e\u8005p\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u7528\u201cxiyou linux\u201d\u6765\u521d\u59cb\u5316\u3002<\/strong><\/p>\n<p>8\u3001\u7528C\u8bed\u8a00\u5b9e\u73b0\u4e00\u4e2an!\u51fd\u6570\u3002\uff08\u8981\u6c42\u7528\u9012\u5f52\u5b9e\u73b0\uff09\u3002<\/p>\n<p>9\u3001 char c;<br \/>\nchar b[20] = \u201cI love xiyou linux\u201d;<br \/>\nc=\u2019l\u2019\u4e0ec=\u201dl\u201d\u6709\u533a\u522b\u4e48\uff1f\u82e5\u6709\uff0c\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u5b57\u7b26\u4e32b\u5728\u5185\u5b58\u4e2d\u5360\u51e0\u4e2a\u5b57\u8282\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><br \/>\n<strong> c=&#8217;l&#8217;\u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u800cc=&#8221;l&#8221;\u662f\u5b57\u7b26\u4e32\u3002<\/strong><br \/>\n<strong> \u4ece\u5bf9b\u6570\u7ec4\u7684\u5b9a\u4e49\u53ef\u4ee5\u5f97\u77e5b\u5728\u5185\u5b58\u4e2d\u5360\u670920\u4e2a\u5b57\u8282\uff0c\u8fd9\u4e0e\u5bf9\u5b83\u8fdb\u884c\u521d\u59cb\u5316\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u65e0\u5173\u3002<\/strong><br \/>\n<strong> \u5982\u679c\u6709\u5982\u4e0b\u5b9a\u4e49\uff1a<\/strong><br \/>\n<strong> char b[] = \u201cI love xiyou linux\u201d;<\/strong><br \/>\n<strong> \u90a3\u4e48\u6b64\u65f6b\u7684\u5927\u5c0f\u4e3a19\u3002<\/strong><\/p>\n<p>10\u3001\u5b9e\u73b0\u81ea\u5df1\u7684strcat()\u3002<\/p>\n<p>11\u3001char str[20] ;<br \/>\nscanf(\u201c%s\u201d, str);<br \/>\nprintf\uff08\u201d%s\u201d,str\uff09;<br \/>\n\u5982\u679c\u8f93\u5165\uff1aI love linux!&lt;\u56de\u8f66&gt;<br \/>\n\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><br \/>\n<strong> \u8f93\u51fa\u7ed3\u679c\u4e3aI\u3002\u56e0\u4e3a\u4f7f\u7528scanf\u8f93\u5165\u5b57\u7b26\u4e32\u65f6\u4e0d\u80fd\u542b\u6709\u7a7a\u683c\uff0c\u5426\u5219\u5b57\u7b26\u4e32\u4f1a\u4ece\u7b2c\u4e00\u4e2a\u7a7a\u683c\u5904\u88ab\u622a\u65ad\u3002<\/strong><\/p>\n<p>12\u3001\u4e0b\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\uff1f<br \/>\n#define MAX(x,y) x &gt; y ? x : y<br \/>\nint main()<br \/>\n{<br \/>\nint a = 10, b = 20;<br \/>\nint c = 3*MAX(a , b);<br \/>\nprintf (\u201c%d\\n\u201d, c);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><br \/>\n<strong> \u7ecf\u8fc7\u5b8f\u66ff\u6362\u540e\uff0cc = 3*a&gt;b?a:b; \u5219c\u7684\u503c\u4e3a10\u3002<\/strong><\/p>\n<p>13\u3001\u5df2\u77e5\u4e24\u4e2a\u6574\u578b\u6570\u7ec4\u5747\u4e3a\u5347\u5e8f\u6392\u5217\uff0c\u5c06\u4e24\u4e2a\u6570\u7ec4\u5408\u5e76\uff0c\u4e14\u5408\u5e76\u540e\u4ecd\u6309\u5347\u5e8f\u6392\u5217\u3002<\/p>\n<p>14\u3001\u4e0b\u9762\u4e24\u6761\u8bed\u53e5\u54ea\u6761\u66f4\u5408\u7406\uff1f<br \/>\nif(array[which] == 5 &amp;&amp; which &lt; SIZE)\u2026..<br \/>\nif(which &lt; SIZE &amp;&amp; array[which] == 5)\u2026.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u662f\u897f\u90aeLinux\u5c0f\u7ec4\u4eca\u5e74\u7eb3\u65b0\u7684\u7b14\u8bd5\u8bd5\u9898\uff0c\u539f\u6587\u5728\u8fd9\u91cc\u3002 1\u3001 \u4e0b\u9762\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f int mai [&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":[],"class_list":["post-3141","post","type-post","status-publish","format-standard","hentry","category-c"],"views":7543,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3141","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=3141"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3141\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3141"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}