【发布时间】:2017-10-09 08:51:55
【问题描述】:
我很好奇为什么这两段代码给出不同的输出
#include <iostream>
using namespace std;
int main(){
char *arr=new char;
arr="monday";
cout<<arr<<endl;//gives the output "monday"
char *newArr=new char[3];//i want array of three pointers not the size of a string to be 2+1
newArr[0]="monday";//err
cout<<newArr[0]<<endl;
system("pause");
return 0;
}
我的意思是他们不是都指向首字母地址的指针
问题是“arr”和“newArr[0]”有什么区别
【问题讨论】: