天下

记录修行的印记

const char* 与char*const的区别

 C++标准规定,const关键字放在类型或变量名之前等价的。
const int n=5//same as below
int const m=10

const   char   *   pstr; //   pstr   是字符指针,它指向的量是   const的,
例如:   char   *m= "hello   world 1";
          
char   *n= "Hello   world 2";
          
const   char   *   pstr=m;
          pstr[
1]= '';   //   it 's   wrong
          pstr=n;             //   it 's   right

char*   const   pstr;//  pstr   是字符指针,这个指针的值必须初始化,初始化以后就不能改变了.
例如:   char   *m= "hello   world 3";
          
char   *n= "Hello   world 4";
          
char*   const   pstr=m;
          pstr
=n;   //   it 's   wrong
          pstr[1]= '';   //   it 's   right

至于   
const   char*   const   pstr   自然是两者的结合了.


posted on 2010-12-23 15:53 天下 阅读(3932) 评论(0)  编辑 收藏 引用 所属分类: C/C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2013年6月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论