码迷,mamicode.com
首页 > 其他好文 > 详细

An error from other projects which impress me most

时间:2017-02-26 01:15:32      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:mem   which   ++   init   define   pre   rem   cannot   not   

I cannot remember what the specific c++ project is, but what impressed me most is the definition of constant pointer.

If we want to define a pointer which the address content is able to change, we can‘t use char const * p, for example:

  1. char const *p;  
  2. p=str;  
  3. *p=‘n‘;  

we will get an error message:

错误: 向只读位置‘*p’赋值

 

char * const p; //define a pointer which the address is unable to change
char const * p;//define a pointer which the address content is unable to change 
const char *p; //the same as char const *p

An error from other projects which impress me most

标签:mem   which   ++   init   define   pre   rem   cannot   not   

原文地址:http://www.cnblogs.com/xiangyiqing/p/6443437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!