看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 這是寫紙本考卷上的題目,所以上面那幾項不知道要寫什麼orz 如果有發文問題還請不吝指正 題目:假設a,b,c三變數分別存放在記憶體位置5000,6000,7000 1.int a = 35; 2.int *b = &a; 3.int **c = &b; 試求b , c , *c , **c , &c 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) 補充說明(Supplement): **c 和 &c 搞不清楚到底要怎麼看 如果這樣發文格式有誤還有請各位提出,謝謝 --
lin79529: 不是我05/06 02:56
buster37: 就是你05/06 03:04
tom282f3: 不可能05/06 03:05
buster37: 納智捷05/06 03:06
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.114.181.124 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1556620116.A.F34.html
school4303: 35 7000 04/30 20:15
ko27tye: c是pointer to pointer 那做兩次dereference會是? 04/30 20:15
ko27tye: &操作放在=右邊又是代表? 04/30 20:17
mazz: 請問一下**c的含意是甚麼?是指向*c嗎? 04/30 21:08
allensheng: 是一個指向指標的指標 名字叫做c 04/30 21:23
roytiu: 畫個圖就會比較好了解 名稱(內容)-位址 04/30 21:35
Gway: 5000 6000 6000 35 7000 ? 05/01 22:39
Gway: 5000 6000 5000 35 7000才對 05/03 20:56
arshuan: 去了解一下 複雜變數宣告的判讀方式會比較清楚 google搜 05/04 12:11
arshuan: 尋一下understand complicated declaration之類的 05/04 12:11
arshuan: b是一個指標指向一個int a的位址 c是一個指標指向一個int 05/04 12:29
arshuan: * b的位址 不加任何*或&的狀況下就是印出那個變數本身 05/04 12:29
arshuan: 存的data. 加*(dereference)就是把那個data視作address 05/04 12:29
arshuan: 去取那個address內的data. **就是取兩次而已 *c是把c 05/04 12:30
arshuan: 所存的b位址視為位址然後取該位址的data也就是a的位址。 05/04 12:30
arshuan: *(*c)就是再進一步把a的位址視為位址取該位址的data 05/04 12:30
arshuan: 也就是35 05/04 12:30
rouyu0741: &c = memory address of c = 7000 05/10 13:53
rouyu0741: c = &b = memory address of b = 6000 05/10 13:53
rouyu0741: *c = *(&b) = b = &a = memory address of a = 5000 05/10 13:53
rouyu0741: **c = *(&a) = a = value of a = 35 05/10 13:54
感謝各位大大的協助! ※ 編輯: mazz (218.173.173.62), 05/12/2019 13:36:33