{"id":248401,"date":"2021-01-01T00:16:34","date_gmt":"2020-12-31T16:16:34","guid":{"rendered":"http:\/\/4563.org\/?p=248401"},"modified":"2021-01-01T00:16:34","modified_gmt":"2020-12-31T16:16:34","slug":"%e8%af%b7%e6%95%99%e5%a4%a7%e5%ae%b6%e4%b8%80%e4%b8%aa-c-%e6%8c%87%e9%92%88%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=248401","title":{"rendered":"\u8bf7\u6559\u5927\u5bb6\u4e00\u4e2a C \u6307\u9488\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\u5927\u5bb6\u4e00\u4e2a C \u6307\u9488\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GromHellscream <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;  int main(int argc, char *argv[]) {  int a[4] = {150, 250, 350, 450};  int * c = a;  printf(\"1: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %dn\", a[0], a[1], a[2], a[3]);  c = c + 1;  printf(\"current c points to %dn\", *c);    c = (int *) ((char *) c + 1);  *c = 500;    printf(\"2: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %dn\", a[0], a[1], a[2], a[3]); } <\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<br \/> 1: a[0] = 150, a[1] = 250, a[2] = 350, a[3] = 450<br \/> current c points to 250<br \/> 2: a[0] = 150, a[1] = 128250, a[2] = 256, a[3] = 450 <\/p>\n<p>\u8bf7\u6559\u4e0b\u5927\u5bb6\uff0c\u6700\u540e a[1] \u548c a[2] \u4e3a\u4ec0\u4e48\u5206\u522b\u53d8\u6210 128250 \u548c 256 \u4e86\uff1f<br \/> \u6c42\u8d50\u6559\uff0c\u8c22\u8c22\uff01<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4824408\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qianlv7 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             c = (int *) ((char *) c + 1); int* \u505a\u8fd0\u7b97\u662f\u6309 4 \u4e2a\u5b57\u8282\u7684, char* \u6307\u9488\u7684\u8fd0\u7b97\u662f 1 \u4e2a\u5b57\u8282\u7684\uff0c \u6240\u4ee5\u8fd9\u53e5 c \u73b0\u5728\u7684\u4f4d\u7f6e\u5c31\u505a 1\uff0c2 \u4e4b\u95f4\u7684\u5185\u5b58\u4e86\uff0c\u7136\u540e*c = 500 \u5c31\u5bfc\u81f4 2 \u4e2a\u4f4d\u7f6e\u7684\u5185\u5b58\u90fd\u4fee\u6539\u4e86\u90e8\u5206                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824409\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : GromHellscream <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @qianlv7 \u597d\u7684\uff0c\u8c22\u8c22\u4f60\u3002\u90a3\u80fd\u7ed9\u51fa\u8fd9\u4e2a 128250 \u548c 256 \u7684\u8ba1\u7b97\u8fc7\u7a0b\u5417\uff1f\u5bfc\u81f4\u8fd9\u4e24\u4e2a\u503c\u7684\u539f\u56e0\u6211\u5927\u6982\u61c2\u4e86\uff0c\u4f46\u600e\u4e48\u7b97\u51fa\u6765\u7684\uff0c\u4e0d\u592a\u61c2\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824410\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : learningman <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6307\u9488+1 \u7684 1 \u6307\u7684\u662f\u6307\u9488\u5bf9\u5e94\u7684\u6570\u636e\u7ed3\u6784\u7684\u5355\u4f4d\u5185\u5b58\u5927\u5c0f\u5427\uff08\u4e0d\u786e\u5b9a\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824411\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qianlv7 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @GromHellscream \u4f60\u5c31\u662f\u4fee\u6539\u4e86 a[1] \u7684\u540e 3 \u4e2a\u5b57\u8282\uff0c\u540e a[2] \u7684\u7b2c\u4e00\u4e2a\u5b57\u8282                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824412\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Lime <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`c<br \/>#include &lt;stdio.h&gt;<br \/>#include &lt;stdlib.h&gt;<\/p>\n<p>int main(int argc, char *argv[]) {<br \/> \/\/ \u770b\u8d77\u6765\u4f60\u662f\u5728 x86_64 \u4e0a\u6765\u8dd1\u7684, int \u4e3a 4-bytes, \u6b64\u65f6\u5185\u5b58\u5e03\u5c40\u4e3a:<br \/> \/\/<br \/> \/\/ a[0]<br \/> \/\/ \u2193<br \/> \/\/ 69000000 af000000 e5100000 2c100000<br \/> int a[4] = {150, 250, 350, 450};<\/p>\n<p> int * c = a;<br \/> printf(&#8220;1: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %dn&#8221;, a[0], a[1], a[2], a[3]);<\/p>\n<p> \/\/ c<br \/> \/\/ \u2193<br \/> \/\/ 69000000 af000000 e5100000 2c100000<br \/> c = c + 1;<br \/> printf(&#8220;current c points to %dn&#8221;, *c);<\/p>\n<p> \/\/<br \/> \/\/ c<br \/> \/\/ \u2193<br \/> \/\/ 69000000 af000000 e5100000 2c100000<br \/> c = (int *) ((char *) c + 1);<br \/> printf(&#8220;%pn&#8221;, c);<\/p>\n<p> \/\/ c<br \/> \/\/ \u2193<br \/> \/\/ 69000000 af4f1000 00100000 2c100000<br \/> \/\/<br \/> \/\/ \u6700\u7ec8:<br \/> \/\/<br \/> \/\/ a[0] = 0x96<br \/> \/\/ a[1] = 0x1f4fa -&gt; 128250<br \/> \/\/ a[2] = 0x100 -&gt; 256<br \/> \/\/ a[4] = 0x1c2<br \/> *c = 500;<\/p>\n<p> printf(&#8220;2: a[0] = %d, a[1] = %d, a[2] = %d, a[3] = %dn&#8221;, a[0], a[1], a[2], a[3]);<br \/>}<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824413\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Lime <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             v2ex \u7f16\u8f91\u56de\u590d\u771f\u662f\u86cb\u75bc<\/p>\n<p>https:\/\/gist.github.com\/shiyanhui\/f22eb5295b48edb46b43dad1ebe54b03 <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824414\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : maxhhg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Lime \u4f60\u7684\u5c0f\u7aef\u5b57\u8282\u5e8f\u9519\u4e86<br \/>[url=https:\/\/imgchr.com\/i\/sCNUY9][img]https:\/\/s3.ax1x.com\/2021\/01\/03\/sCNUY9.png[\/img][\/url]                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824415\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Lime <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @maxhhg fixed                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4824416\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yyttll <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             32 \u4f4d\u673a\u5668 int \u5360 4 \u4e2a\u5b57\u8282\uff0cchar \u5360 1 \u4e2a\u5b57\u8282\uff0cint \u6307\u9488\u52a0 1\uff0c\u5176\u503c\u52a0 4\uff0cchar \u6307\u9488\u52a0 1\uff0c\u5176\u503c\u52a0 1 \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\u5927\u5bb6\u4e00\u4e2a C \u6307\u9488\u7684\u95ee\u9898 \u8cc7\u6df1&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/248401"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=248401"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/248401\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=248401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=248401"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=248401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}