Fun with pointer!,funwithpointer

來源:互聯網
上載者:User

Fun with pointer!,funwithpointer
 int x=1; //x的地址為50

語句 p *p x
int x=1; const int *p =&x; 50 可以修改 int y=2;p=&y,此時p和*p都變 1  不能修改 可以改變。x=2,此時*p=2,但p不變
const int x=1;const int *p=&x; 50 不可修改 1 不可修改 不可修改
const int x=1;int *p=&x; 出錯  只能常量指標才可以指向常量    
int x=1; int *const p=&x; 50 不可修改 *p=3;則x=3.但p不變 可以改變。*p對應改變,但是p不變
int x=1;const int *const p=&x; 50 不可修改 不可修改
可以改變。x=2,此時*p對應改變但p不變

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.