Re: [問題] hw1.2.p1b(iv)
: --
: ※ 發信站: 批踢踢實業坊(ptt.cc)
: ◆ From: 111.248.105.212
: 推 nianze:請問為甚麼P1a的大小是16bytes?我用sizeof(P1a)得到8bytes 10/05 17:23
: → nianze:而且string+int=8bytes好像很合理?請老師再多解釋一點謝謝 10/05 17:25
哦,P1a 的 size 應該是 platform independent.
"string" 在 32 & 64 bit machine 的 size 分別為 4 & 8 Bytes,
所以在 32 bit machine 是 8 Bytes 無誤,
但在 64-bit machine 由於 memory allignment 的關係,
會在 int _dummy 與 string _str 之間塞入 4 Bytes,
讓總 size 變成 16 Bytes.
: 推 nianze:另外,既然arr1b_3[i]是P1a*,那derefernce後不就是P1a了嗎 10/05 17:28
不確定你為什麼要 dereference...
The content of arr1b_3[i] 就直接 "cout << arr1b_3[i]" 就好了,
所以印出來的是一個 memory address 指向存 P1a 的 memory.
如果你 dereference 再印,像是 "cout << *(arr1b)3[i]",
compiler 應該會 complain "operator << (...)" not defined 吧!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.248.105.212
※ 編輯: ric2k1 來自: 111.248.105.212 (10/05 22:52)
→
10/05 22:53, , 1F
10/05 22:53, 1F
推
10/05 22:58, , 2F
10/05 22:58, 2F
→
10/05 22:59, , 3F
10/05 22:59, 3F
討論串 (同標題文章)