#include "stdafx.h"
#include <iostream>
using namespace std;
void main(void)
{
char* str = "0123456789";
strcpy( str+3 ,"ABCD");
cout << str <<endl;
}
#include "stdafx.h"
#include <iostream>
using namespace std;
void main(void)
{
char str[] = "0123456789";
strcpy( str+3 ,"ABCD");
cout << str <<endl;
}
两个一个会报错,一个结果是 012ABCD。
面试我的大哥 非说在c++ 中 2者是一样的。 我的环境是 vs2008 c++ 工程 。第一个肯定会报错的啊。第一个是一个字符串常量,不可修改的,指针只是指向那块区域。面试大哥跟我说,只要能获得指针,只要不是const,就可以修改内容。无语。