palhade
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,
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,
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.
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.
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;
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.codeguru.com/cpp/cpp/cpp_mfc/general/article.php/c6967