我有以下问题:字符数组VS int数组
int a[2][2]={{1,2},{3,4}};
cout<<a[1]; //the output is 0x29ff18 , which is an address
--------------------------------------------------------------------
char b[][6]={"hello","there","now"};
cout<<b[1]; //the output is there, which is value of b[1]
我很奇怪,为什么B [1]将不会给出[1] ...
感谢像一个地址!
'a [1]'和'b [1]'是数组,不是地址。但这与你的表面问题无关。 –
我不知道为什么结果会不同 – jackycflau
表达式'b [1]'被隐式转换为'char *','char *'的流重载打印一个字符串,如果你想要的地址需要强制转换:'std :: cout << static_cast(b [1]);'。它在'a'的情况下打印地址,因为'int *'没有更好的重载。 –
user657267