Possible Duplicate:
what is the difference between const int*, const int * const, int const *
constant pointer
Is there any difference between these two statements?
void * const sam;
and
void const *sam;
Possible Duplicate:
what is the difference between const int*, const int * const, int const *
constant pointer
Is there any difference between these two statements?
void * const sam;
and
void const *sam;
void * const sam;
the pointer is read-only. The qualifier is after the *
.
void const *sam;
the pointee is read-only. The qualifier is before the *
.
const int * Constant
declares that Constant is a variable pointer to a constant integer and
int const * Constant
is an alternative syntax which does the same, whereas
int * const Constant
declares that Constant3 is constant pointer to a variable integer and
Source:
http://duramecho.com/ComputerInformation/WhyHowCppConst.html
Yes.
After changing void
to int
int * const sam;
sam = NULL; /* invalid */
*sam = 42; /* valid */
or
int const *sam;
sam = NULL; /* valid */
*sam = 42; /* invalid */