課程
/后端開發
/C++
/C++遠征之離港篇
指針指向const修飾的變量時,int const a=3;const int const*p=&a和const int *p=&a有啥區別,后者對嗎
2015-11-12
源自:C++遠征之離港篇 3-4
正在回答
const int const *p = &a; // *p 和 p均為常量
const int *p = &a; // *p 為常量 ,p是變量(可以指向其它地址)
雨晴香指醉人頭 提問者
鋼琴上的芭蕾
應該寫成const int* const p = &a; 嗎
const int const*p 這種寫法編譯器會報錯的! 兩個const都是修飾int的,重復了。
const int *p 和 int const *p 這兩種寫法是一樣的,都是將p聲明為指向const int的指針。
舉報
C++掃清通往面向對象的最后一道障礙,將所有知識點融會貫通
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-11-12
const int const *p = &a; // *p 和 p均為常量
const int *p = &a; // *p 為常量 ,p是變量(可以指向其它地址)
2017-02-22
應該寫成const int* const p = &a; 嗎
2015-11-12
const int const*p 這種寫法編譯器會報錯的! 兩個const都是修飾int的,重復了。
const int *p 和 int const *p 這兩種寫法是一樣的,都是將p聲明為指向const int的指針。