What is the difference between char * const and const char *?

前端 未结 19 1173
执笔经年
执笔经年 2020-11-22 03:31

What\'s the difference between:

char * const 

and

const char *
19条回答
  •  太阳男子
    2020-11-22 03:41

    I would like to point out that using int const * (or const int *) isn't about a pointer pointing to a const int variable, but that this variable is const for this specific pointer.

    For example:

    int var = 10;
    int const * _p = &var;
    

    The code above compiles perfectly fine. _p points to a const variable, although var itself isn't constant.

提交回复
热议问题