Link to home
Start Free TrialLog in
Avatar of palhade
palhadeFlag for India

asked on

Constant Pointers and Pointers to Constants

Hi,

I want to know the exact difference between "Constant Pointers and Pointers to Constants"
I want to know it in detail.

Please give some example to understand and practice.

Thanks and Regards,

Avatar of alb66
alb66
Flag of Italy image

Avatar of evilrix
Constant Pointers: The pointer itself is constant and cannot be changed to point to anything else but the object being pointer to can be modified

Pointers to Constants: The object being pointer to is constant and cannot be modified, but the pointer can

You can also have Constant Pointers pointing to Constants, which means neither the pointer nor the object it points to can be modified.
Avatar of palhade

ASKER

some example please to better understand
// how to declare a pointer to a constant character
const char * myPtr = &char_A;

// how to declare a constant pointer to a character.
char * const myPtr = &char_A;

// how to declare a constant pointer to a constant character.
const char * const myPtr = &char_A;





SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial