`
wss71104307
  • 浏览: 219138 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

char * 与 char []

 
阅读更多

There is an important difference between these definitions:

char amessage[] = "now is the time"; /* an array */
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.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics