Proper Way To Initialize Unsigned Char*

前端 未结 7 2147
渐次进展
渐次进展 2021-02-04 06:03

What is the proper way to initialize unsigned char*? I am currently doing this:

unsigned char* tempBuffer;
tempBuffer = \"\";

<
7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 06:29

    It depends on what you want to achieve (e.g. do you ever want to modify the string). See e.g. http://c-faq.com/charstring/index.html for more details.

    Note that if you declare a pointer to a string literal, it should be const, i.e.:

    const unsigned char *tempBuffer = "";
    

提交回复
热议问题