作者ienxk4 (阿佐谷)
看板C_and_CPP
標題[問題] C++ 陣列問題
時間Sun Sep 13 18:41:54 2009
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void)
{
int a[]={1,2,3};
cout << "a=" << a << endl;
char b[]="David";
cout << "b=" << b << endl;
system("pause");
return 0;
}
==================================
執行結果為:
a=0x22ff60
b=David
==================================
我的疑問是int a[] 輸出的是陣列起始位址
而char b[] 輸出的為何不是位址呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.99.99
1F:→ james732:這是 cout 動的手腳 09/13 18:44
2F:推 hilorrk:static_cast<void *> 09/13 18:50
3F:推 holymars:operator << 被overload過,吃到char *的時侯會輸出字串 09/13 19:37