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

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

What\'s the difference between:

char * const 

and

const char *
19条回答
  •  鱼传尺愫
    2020-11-22 03:48

    I remember from Czech book about C: read the declaration that you start with the variable and go left. So for

    char * const a;
    

    you can read as: "a is variable of type constant pointer to char",

    char const * a;
    

    you can read as: "a is a pointer to constant variable of type char. I hope this helps.

    Bonus:

    const char * const a;
    

    You will read as a is constant pointer to constant variable of type char.

提交回复
热议问题