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


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

<2007年6月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜