What’s the difference between
char* name
which points to a constant string literal, and
const char* name
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
char*is a mutable pointer to a mutable character/string.const char*is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion fromconst char *tochar*is deprecated.char* constis an immutable pointer (it cannot point to any other location) but the contents of location at which it points are mutable.const char* constis an immutable pointer to an immutable character/string.