cosmordinary

In this infinite cosmos we have only one life each. A life in this infinite cosmos is just like a dust in the world. Born by chance and die in necessity. Feeble life and boundless world, two facts we face. Even if you spend your whole life solving them. You will get nothing. - 1998

Thursday, November 23, 2006

"const int * x" vs. "int * const x"

The second way to use const makes it impossible to
change the value of the pointer itself:

int sloth = 3;

const int * ps = // a pointer to const int

int * const finger = // a const pointer to int


Note that the last declaration has repositioned the keyword
const. This form of declaration constrains finger to point
only to sloth. However, it does allow you to use finger to
alter the value of sloth. The middle declaration does not allow you to
use ps to alter the value of sloth, but it does permit you to
have ps point to another location. In short, finger and
*ps are both const, and *finger and ps are
not const.

0 Comments:

Post a Comment

<< Home