3-3的答案錯了吧?
這個答案錯了吧?
如果僅僅要指針可指向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;` 是什么意思?
這個答案錯了吧?
如果僅僅要指針可指向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
舉報
2019-03-17
當const已經(jīng)修飾一直變量時,再去用指針去指這個變量會很危險,因為指針可以改去該變量的值,與const就有沖突的風險,const int *p=&a和const int * const p=&a是可以的,這樣保證了*p的值不能改變,所以就不會有與const沖突的可能性。
2018-02-19
答案是const int *p = &count;吧。題目只要求“定義指針p引用變量count”,沒說p也要const。所以不用const int const *p = &count;