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

导航

<2007年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜