您的位置:首页 > 其它

指针与数组的区别

2013-03-29 08:33 225 查看
char *buf1="hello";

char *buf2="hello";

if(buf1==buf2)

cout<<"equal"<<endl;

else

cout<<"unequal"<<endl;

2.
char buf1[10]="hello";

char buf2[10]="hello";

if(buf1==buf2)

cout<<"equal"<<endl;

else

cout<<"unequal"<<endl;

指针是常量,不能改变字符串中字符的值

char *p="abc";

p="cde";

// p[1]='m'; 这句编译可以通过,但是运行就出错了

cout<<"p="<<p<<endl; 打印出cde

cout<<"p[1]="<<p[1]<<endl; 打印出d

答案:输出分别为equal unequal.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: