字符数组使用问题

来源:互联网 发布:装修公司网站php源码 编辑:程序博客网 时间:2024/05/16 19:17
                          字符数组使用问题
下面看两个Demo;
demo1:
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{

    char *ch1="chdjlfjdalfj";
 ch1[2]='y';    // 在vc6下编译连接没有任何错误,运行时出现错误
 cout<<ch1;
 return 0;
}

demo1 在vc6下编译连接没有任何错误,运行时出现运行时错误!!
下面看demo2:
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
 char ch2[]="jdkljfdljf";
 ch2[3]='o';             //  没有任何错误
 cout<<ch2;
 return 0;
}