char* 和 const char* 之间的区别? [英] Difference between char* and const char*?
问题描述
和
char* name
指向一个常量字符串文字,以及
which points to a constant string literal, and
const char* name
推荐答案
char*
是一个 mutable 指针,指向一个 mutable 字符/字符串.
char*
is a mutable pointer to a mutable character/string.
const char*
是一个可变指针,指向一个不可变字符/字符串.您不能更改此指针指向的位置的内容.此外,当您尝试这样做时,编译器需要给出错误消息.出于同样的原因,不推荐从 const char *
转换为 char*
.
const char*
is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char *
to char*
is deprecated.
char* const
是一个不可变指针(它不能指向任何其他位置)但是它指向的位置的内容是可变.
char* const
is an immutable pointer (it cannot point to any other location) but the contents of location at which it points are mutable.
const char* const
是一个 immutable 指针,指向一个 immutable 字符/字符串.
const char* const
is an immutable pointer to an immutable character/string.
这篇关于char* 和 const char* 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!