char a[6]="hello";
char b[5]={'t','e','s','t','\0'};
int c[]={1,2,3,4,5};
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
输出结果
hello
test
一串地址
为什么会有这种区别呢?
char a[6]="hello";
char b[5]={'t','e','s','t','\0'};
int c[]={1,2,3,4,5};
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
输出结果
hello
test
一串地址
为什么会有这种区别呢?
3 回答2k 阅读✓ 已解决
2 回答3.9k 阅读✓ 已解决
2 回答3.2k 阅读✓ 已解决
1 回答3.2k 阅读✓ 已解决
1 回答2.7k 阅读✓ 已解决
3 回答3.4k 阅读
1 回答3.3k 阅读
char *或者char []类型就默认以字符串形式输出
int []类型变量本质是这个数组的第一个元素的地址,所以输出的是地址
当然char *和char []也是地址,你要用
printf("%x", a);
输出的一样是地址