cfmonkey的笔记本

字符数组和字符常量指针

There is an important difference between these definitions:

.
   1:     char amessage[] = "now is the time"; /* an array */
   2:     char *pmessage = "now is the time"; /* a pointer */


amessage is an array, just big enough to hold the sequence of characters and '\0' that initializes it. Individual characters within the array may be changed but amessage will always refer to the same storage. On the other hand, pmessage is a pointer, initialized to point to a string constant; the pointer may subsequently be modified to point elsewhere, but the result is undefined if you try to modify the string contents.


--《the TCPL》K&R

posted on 2007-06-17 02:06 cfmonkey 阅读(190) 评论(0)  编辑 收藏 引用

导航

<2009年8月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜