Consider the domain of character strings; for example, the phrase hello world. In C, the lingua franca for dealing with strings was char *:
char *greet(const char *name) {
char buffer[100];
snprintf(buffer, 100, "hello %s", name);
return strdup(buffer);
}
void test() {
const char *who = "world";
char *hw = greet(who);
assert(strcmp(hw, "hello world") == 0);
free(hw);
}
This was all right for a while, but dealing with raw char *s had some problems for the users of the language and the creators of third-party libraries and routines. For one thing, the C language was so old that const had not been invented at the outset, which meant that certain old routines would expect their strings as char * and certain newer ones expect const char *. For another thing, char * didn't carry...