1.const char* p: p is a pointer to const char(char const* p 一样) 意思就是不能通过p指针来修改p指向的内容(但是内容可以修改). 2.char* p : p is a pointer to char 意思就是可通过p指针来修改p指向的内容 3.char* const p: p is a const pointer to char 意思就是p指针是一个常指针,他指向的内存地址不能变,定义的时候就得初始化 一旦给…
const char*, char const*, char*const的区别问题几乎是C++面试中每次都会有的题目. 事实上这个概念谁都有只是三种声明方式非常相似很容易记混. Bjarne在他的The C++ Programming Language里面给出过一个助记的方法: 把一个声明从右向左读. char * const cp; ( * 读成 pointer to ) cp is a const pointer to char const char * p; p is a…
http://stackoverflow.com/questions/3228664/why-am-i-able-to-change-the-contents-of-const-char-ptr I passed a pointer ptr to a function whose prototype takes it as const. foo( const char *str ); Which according to my understanding means that it will n…