: The declarations
const int ci = 10, *pc = &ci, *const cpc = pc, **ppc;
int i, *p, *const cp = &i;
declare
ci,
a constant integer;
pc,
a pointer to a constant integer;
cpc,
a constant pointer to a constant integer;
ppc,
a pointer to a pointer to a constant integer;
i,
an integer;
p,
a pointer to integer; and
cp,
a constant pointer to integer
. The value of
ci,
cpc,
and
cp
cannot be changed after initialization
. The value of
pc
can be changed, and so can the object pointed to by
cp. Examples of
some correct operations are
i = ci;
*cp = ci;
pc++;
pc = cpc;
pc = p;
ppc = &pc;
Examples of ill-formed operations are
ci = 1; ci++; *pc = 2; cp = &ci; cpc++; p = pc; ppc = &p;
Each is unacceptable because it would either change the value of an object declared
const
or allow it to be changed through a cv-unqualified pointer later, for example:
—
end example