c++ - const char * const versus const char *? -
i'm running through example programs refamiliarize myself c++ , have run following question. first, here example code:
void print_string(const char * the_string) { cout << the_string << endl; } int main () { print_string("what's up?"); } in above code, parameter print_string have instead been const char * const the_string. more correct this?
i understand difference 1 pointer constant character, while 1 constant pointer constant character. why both of these work? when relevant?
the latter prevents modifying the_string inside print_string. appropriate here, perhaps verbosity put off developer.
char* the_string : can change char the_string points, , can modify char @ points.
const char* the_string : can change char the_string points, cannot modify char @ points.
char* const the_string : cannot change char the_string points, can modify char @ points.
const char* const the_string : cannot change char the_string points, nor can modify char @ points.
Comments
Post a Comment