char* vs const char* as a parameter

后端 未结 5 490
逝去的感伤
逝去的感伤 2021-01-30 05:10

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 com

5条回答
  •  一向
    一向 (楼主)
    2021-01-30 05:49

    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.

提交回复
热议问题