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.
char * 与 char []
本文探讨了C语言中字符数组与字符指针之间的关键差异。通过实例对比,阐述了两者在内存分配、修改字符串内容方面的不同行为。文章强调了理解这些概念对于避免运行时错误的重要性。

被折叠的 条评论
为什么被折叠?



