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


只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理


导航

<2026年1月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜