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 阅读(198) 评论(0)  编辑 收藏 引用

导航

<2025年10月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜