2016-10-03 4 views
0

私はかなり新しいです。誰かが私に以下の違いを説明することができますか?使用法とコンセプトの両方で定数ポインタとC定数のポインタとの差

または私がこの概念を完全に理解するのに役立つポインタの使用法の変形です。

答えて

1

constは、1)ポインタ自体(初期化後に別のものを指すように変更できるかどうか)、および2)ポインタが指し示すデータ(ポインターを介してデータが変更できるかどうか)に適用されます。

int *const p= &x; // p is const pointer to non-const data - p cannot change to point to something else, but you can change what it points to 

int const *p= &x; // p is non-const pointer to const data - p can change to point to something else, but what it points to cannot be changed 

const int *const p= &x; // p is const pointer to const data - p cannot change to point to something else, and what it points to cannot be changed 
関連する問題