p等於0,那p+1是多少呢?

來源:互聯網
上載者:User

 

C語言的程式片段:

 

p = 0;

printf("%d\n%d\n", p, p+1);

結果會是什麼呢?

0

呵呵,上當了吧,此題是無解的,因為我沒說p是什麼東西。下面我告訴你p是什麼:

 

int (*p)[1024];
p = 0;

printf("%d\n%d\n", p, p+1);

 

 

結果是:

0

4096

這個結果對嗎?

不一定。還得看它的運行平台。上面的結果是32位Intel平台的,64位的呢?單片機呢?DSP呢?

歡迎有條件的朋友試一試。

最後來個完整的:

 

#include <stdio.h>

int main()
{
int (*p)[1024];
p = 0;
printf("%d\n%d\n", p, p+1);
printf("%d\n%d\n", (int)p, (int)p+1);
printf("%d\n%d\n", (int)p, (int)(p+1));

return 0;
}

 

 

 結果是:

0
4096
0
1
0
4096

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.