const char pointer assignments

前端 未结 4 2119
借酒劲吻你
借酒劲吻你 2020-12-10 17:02

Are the following assignments valid? Or will any of these create problems. Please suggest.

const char * c1;  
const char * c2; 
const char * c3;
char * c4;

         


        
4条回答
  •  醉梦人生
    2020-12-10 17:52

    These assignments are all perfectly valid as I and others have explained in your recent run of near identical questions.

    A const char* is a pointer to memory that cannot be modified using that pointer. Nothing here can circumvent that. The compiler would object if you assigned c4 = c1 since then that would circumvent the const.

提交回复
热议问题