-2

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;
Community
  • 1
  • 1
danny
  • 1,587
  • 2
  • 12
  • 12
  • Is it just me, or are the people using `void *sam` syntax more prone to ask this question than the ones who use `void* sam`? – Lundin Aug 21 '12 at 11:38

3 Answers3

2
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 *.

ouah
  • 142,963
  • 15
  • 272
  • 331
0
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

p.streef
  • 3,652
  • 3
  • 26
  • 50
0

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 */
pmg
  • 106,608
  • 13
  • 126
  • 198