C语言指针数组的问题

写一个如下程序:
char p[]={"world"};
cout<<p[0]<<endl;
得到结果是p[0]为w,
在p前加个指针,得到:
char *p[]={"world"};
cout<<p[0]<<endl;
输出p[0]为world。
请问这两个程序之间有什么不同吗?为什么p[0]指向的结果不一样?

以上代码段
char p[]={"world"};
cout<<p[0]<<endl;
p[0]的类型是字符类型,cout会按照字符输出;
char *p[]={"world"};
cout<<p[0]<<endl;
p[0]的类型是字符指针,cout会按照字符串输出。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-06-18
int* arr[2]={&a,&b,&c};
数组大小为2 , 你却给它赋3个值
相似回答