重複の可能性: const int*、const int * const、int const *定数ポインター
の違いは何ですか
これら2つのステートメントに違いはありますか?
void * const sam;
と
void const *sam;
void * const sam;
ポインターは読み取り専用です。修飾子は . の後にあり*
ます。
void const *sam;
指示先は読み取り専用です。修飾子は の前にあり*
ます。
const int * Constant
Constant が定数整数への変数ポインターであることを宣言し、
int const * Constant
同じことを行う代替構文ですが、
int * const Constant
Constant3 が可変整数への定数ポインターであることを宣言し、
ソース:
http://duramecho.com/ComputerInformation/WhyHowCppConst.html
はい。
void
に変更後int
int * const sam;
sam = NULL; /* invalid */
*sam = 42; /* valid */
また
int const *sam;
sam = NULL; /* valid */
*sam = 42; /* invalid */