3-3的答案錯(cuò)了吧?
這個(gè)答案錯(cuò)了吧?
如果僅僅要指針可指向const定義的變量,只用`const int *p = &a;` 或 `int const *p = &a;` 就可以了吧。
?如果要指針指向也不可修改,那么不應(yīng)該是 `const int *const p = &a;` 或者 `int const *const p = &a;`嗎??
?答案的 `const int const *p = &a;` 是什么意思?
這個(gè)答案錯(cuò)了吧?
如果僅僅要指針可指向const定義的變量,只用`const int *p = &a;` 或 `int const *p = &a;` 就可以了吧。
?如果要指針指向也不可修改,那么不應(yīng)該是 `const int *const p = &a;` 或者 `int const *const p = &a;`嗎??
?答案的 `const int const *p = &a;` 是什么意思?
2018-02-13
舉報(bào)
2019-03-17
當(dāng)const已經(jīng)修飾一直變量時(shí),再去用指針去指這個(gè)變量會(huì)很危險(xiǎn),因?yàn)橹羔樋梢愿娜ピ撟兞康闹担cconst就有沖突的風(fēng)險(xiǎn),const int *p=&a和const int * const p=&a是可以的,這樣保證了*p的值不能改變,所以就不會(huì)有與const沖突的可能性。
2018-02-19
答案是const int *p = &count;吧。題目只要求“定義指針p引用變量count”,沒(méi)說(shuō)p也要const。所以不用const int const *p = &count;