const char and static const char

The version with const char * will copy data from a read-only location to a variable on the stack.

The version with static const char * references the data in the read-only location (no copy is performed).

在函数内部。const char *每次调用函数时,都须要在stack上分配内存,然后将数据拷贝过来,函数退出前释放。

static const char *,会直接訪问read only的数据,无需再stack上分配内存。

char * const cp     : 定义一个指向字符的指针常数,即const指针

const char* p       : 定义一个指向字符常数的指针

char const* p       : 等同于const char* p


posted on 2016-01-11 13:19  gcczhongduan  阅读(629)  评论(0编辑  收藏  举报