Pointer to constant does not allow to change the value at the address pointed by pointer ( *ptr). 1. const int *ptr = 3; 2. int const *ptr; // 1 and 2 both are having same meaning. *ptr = 5; // not allowed Constant pointer does not allow to change the address to which pointer is pointing. int i = 10; int * const ptr = &i; int j =80; ptr = &j; // not allowed. constant pointer to constant data int i = 9; const int * const ptr = &i; int j =90; *ptr =10; // not allowed ptr = &j; // not allowed.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
1. const int *ptr = 3;
2. int const *ptr; // 1 and 2 both are having same meaning.
*ptr = 5; // not allowed
Constant pointer does not allow to change the address to which pointer is pointing.
int i = 10;
int * const ptr = &i;
int j =80;
ptr = &j; // not allowed.
constant pointer to constant data
int i = 9;
const int * const ptr = &i;
int j =90;
*ptr =10; // not allowed
ptr = &j; // not allowed.