char *s="Golden Global View";
中的"Golden Global View"是字符串常量,是存储在数据段,和int a = 5中的5类似.

const char str[] = "Golden Global View";
中的const是告诉给编译器str中的数据不能修改.数据是存储在堆栈段的.但是还是可以修改的.

详情,可以参考帖子:
http://www.programfan.com/club/post-240796.html

在该帖子中有以下内容:

//a.c
#include <stdio.h>
#include <string.h>

int main()
{
        char *s="Golden Global View";
        char *l="lob";
        char *p;        
        p=strstr(s,l);
        *p='\0';
        printf("%s",s);
}

想输出lob前面的字符串,也就是Golden G  
但是运行时出错,调试时也说有错误
原因是:
char *s="Golden Global View";是分配在常量区得,不能修改 ( *p='\0';)!
改成char s[] = "Golden Global View";

相关文章:

  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2021-11-28
  • 2021-05-26
  • 2021-11-30
相关资源
相似解决方案