I'm running through some example programs to refamiliarize myself with C++ and I have run into the following question. First, here is the example code:
void print_string(const char * the_string)
{
cout << the_string << endl;
}
int main () {
print_string("What's up?");
}
const char * const the_string
The latter prevents you from modifying the_string
inside print_string
. It would actually be appropriate here, but perhaps the verbosity put off the developer.
char* the_string
: I can change the char
to which the_string
points, and I can modify the char
at which it points.
const char* the_string
: I can change the char
to which the_string
points, but I cannot modify the char
at which it points.
char* const the_string
: I cannot change the char
to which the_string
points, but I can modify the char
at which it points.
const char* const the_string
: I cannot change the char
to which the_string
points, nor can I modify the char
at which it points.