C Programming – char* vs const char* as Function Parameters

c++

There are many times that I get compile errors when I use char* instead of const char*. So, I am not sure the actual difference, the syntax and the compile mechanism.

Best Answer

If you're after the difference between the two, just think of them as:

  • char* is a pointer that points to a location containing a value of type char that can also be changed. The pointer's value can be changed, i.e. the pointer can be modified to point to different locations.
  • const char* is a pointer, whose value can be also changed, that points to a location containing a value of type char that cannot be changed.