When to use const char * and when to use const char []

前端 未结 6 1610
梦毁少年i
梦毁少年i 2020-12-04 08:39

I know they are different, I know how they are different and I read all questions I could find regarding char* vs char[]

But all those answ

6条回答
  •  甜味超标
    2020-12-04 09:13

    If you use an array, then the data is initialized at runtime. If you use the pointer, the run-time overhead is (probably) less because only the pointer needs to be initialized. (If the data is smaller than the size of a pointer, then the run-time initialization of the data is less than the initialization of the pointer.) So, if you have enough data that it matters and you care about the run-time cost of the initialization, you should use a pointer. You should almost never care about those details.

提交回复
热议问题