提问,char msg[]和 char *msg 使用区别

C语言 码拜 8年前 (2016-04-27) 2157次浏览
#include<stdio.h>
#include<string.h>
void fit(char *,unsigned int);
int main()
{
char mesg[] = “Hold on to your hats,hackers. “;
fit(mesg,7);
puts(mesg);
return 0;
}
void fit(char *string,unsigned int size)
{
if(strlen(string) > size)
{
*(string + size) = “\0”;
}
}
看C prime plus课本时,使用以上程序演示缩短字符串长度函数功能,程序编译通过。
但本人将  char mesg[] = “Hold on to your hats,hackers. “;
修改为: char *mesg = “Hold on to your hats,hackers. “; 编译时提示出错。
请哪位高手指点下,万分感谢!
解决方案

80

可以这样理解

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明提问,char msg[]和 char *msg 使用区别
喜欢 (0)
[1034331897@qq.com]
分享 (0)