const usage summary (incomplete)

const usage summary (incomplete)

1.const char *, char const * and char * const difference

. 1) const char *
by definition const char * pointer to a pointer can not be used to modify the contents can be modified using the original variable is pointed. However, const char * pointer can change the contents defined points.
E.g:

char a[100]="Hello world!";
const char *p;
p=a;
p='a';  //错误,不能用该指针修改a中的内容
a[0]='a';//正确
p++;     //该指针可以修改指向的内容

const char * and char const * equivalent.
2) char * const
with char * const defined pointer with a pointer contents may be modified, but can not change the pointer points.

char a[100] = "Hello world!";
char * const p = a;  //该指针必须在定义时指向
*p = 'a';            //用该指针可以修改a的值,等价于a[0] = 'a';
p++;                 //错误,该指针不可改变指向
Released two original articles · won praise 0 · Views 68

Guess you like

Origin blog.csdn.net/li_wen_zhuo/article/details/104056401