字符* VS为const char *作为参数 [英] char* vs const char* as a parameter
本文介绍了字符* VS为const char *作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有很多次,我得到的,当我使用编译错误的char *
而不是为const char *
。所以,我不知道实际的差别,语法和编译机制。
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.
推荐答案
如果你是两者之间的区别后,就认为他们是:
If you're after the difference between the two, just think of them as:
- 的char * 是指向包含char类型的值,也可以改变位置的指针。指针的值是可以改变的,即,指针可以被修改为指向不同的位置。
- 为const char * 是一个指针,谁的价值也可以改变,即指向包含char类型的的值的位置不能来改变。
- 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, who's value can be also changed, that points to a location containing a value of type char that cannot be changed.
这篇关于字符* VS为const char *作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文