const char * means you cannot use a pointer to change what it points to. You can change the pointer to point to something else.
Consider:
const char * promptTextWithDefault(const char * text) { if ((text == NULL) || (*text == '\0')) text = "C>"; return text; }
The parameter is a non-constant pointer to const char, so it can be changed to another const char * value (for example, a constant string). If, however, we mistakenly wrote *text = '\0' , then we would get a compilation error.
Perhaps if you are not going to change what this parameter points to, you can make the const char * const text parameter, but it is not. Usually we allow functions to change the values โโpassed to the parameters (since we pass parameters by value, any change does not affect the caller).
By the way: it is good practice to avoid char const * , because it is often read incorrectly - this means the same as const char * , but too many people read it as a char * const value.
TonyR Dec 29 '15 at 11:28 2014-12-29 11:28
source share