[問題] C++ 陣列問題

看板C_and_CPP (C/C++)作者 (阿佐谷)時間16年前 (2009/09/13 18:41), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/2 (看更多)
#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

09/13 18:44, , 1F
這是 cout 動的手腳
09/13 18:44, 1F

09/13 18:50, , 2F
static_cast<void *>
09/13 18:50, 2F

09/13 19:37, , 3F
operator << 被overload過,吃到char *的時侯會輸出字串
09/13 19:37, 3F
文章代碼(AID): #1AhCnpRo (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1AhCnpRo (C_and_CPP)