Re: [問題] hw1.2.p1b(iv)

看板EE_DSnP作者 (Ric)時間10年前 (2013/10/05 22:51), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串3/3 (看更多)
: -- : ※ 發信站: 批踢踢實業坊(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
上次下課有人來問我 string 的 size,我跟他講錯了!
10/05 22:53, 1F

10/05 22:58, , 2F
我是想要確定arr1b_3[i]指向的東西的大小是多少 原本以為
10/05 22:58, 2F

10/05 22:59, , 3F
變成16bytes 和題目要求無關 謝謝老師解答!
10/05 22:59, 3F
文章代碼(AID): #1IK2TdyG (EE_DSnP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
文章代碼(AID): #1IK2TdyG (EE_DSnP)