现在的位置: 首页 > 综合 > 正文

const 与指针 还是英文描述准确

2013年10月14日 ⁄ 综合 ⁄ 共 587字 ⁄ 字号 评论关闭

“指针常量” 和“常量指针” 很容易理解出问题(至少我是这样滴),感觉还是英文说的比较准确。

一篇讨论const 与指针的英文文章

http://www.codeguru.com/cpp/cpp/cpp_mfc/general/article.php/c6967/Constant-Pointers-and-Pointers-to-Constants.htm

如果懒得去仔细看英文,这里有个简单总结:

1. “指针常量”

     ==“指针本身是常量”

     =="指针保存的内容不能修改,即只能指向初始化时的变量"

     ==“constant pointer”

     ==“The location stored in the pointer cannot change. You cannot change where this pointer points

     example:

     char *const myPtr;

2. “常量指针”

     =="指向常量的指针”

     ==“指针本身可以修改,但不能通过该指针修改指向的对象,即(*pointer)是不能修改的”

     ==“pointer to constant"

     =="You cannot use this pointer to change the value being pointed to"

     example:

     const char* myPtr;

over!

抱歉!评论已关闭.