#include <stdio.h>
#include <string.h>
void print(char *c)
{
c[0]='A'; //有时候我们想要这样一个函数,仅允许读,但是不允许写。我们可以把函数的参数修改为const
while(*c!='\0')
{
printf("%c",*c);
c++;
}
}
int main()
{
char c[20]="hello"; //字符串会存在分配给这个数组的内存空间中,这种情形下它会被分配在栈上
//char *c="hello"; //编译期间会把它们分配在常量区,最有可能会被放在应用程序的代码区,结果是它不能被修改,c[0]='A'就会报错
print(c);
return 0;
}
C语言指针和字符数组(下)
最新推荐文章于 2024-06-17 20:25:43 发布