c++指针分配内存的问题,求各位大神解答

2024-11-30 12:33:20
推荐回答(3个)
回答1:

因为 “123” 是常量 是无法修改的

回答2:

发个程序块你参考一下:
#include
using namespace std;
int main()
{
int i;
char *pcity[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
char **pcity;
cout<<"输入数值(1~7):";
cin>>i;
pcity=pcity+i-1;
cout<<*pcity<return 0;
}

回答3:

#include 
using namespace std;
int main()
{
char pcity[16] = "123";    //
cout << "input " << endl;
cin >> pcity;
cout << "output " << pcity << endl;
}