※ 本文轉寄自 ptt.cc, 文章原始頁面
[問題] c pointer to array address 請教
開發平台(Platform): (Ex: Win10, Linux, ...)
online c compiler
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
gcc
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
NA
問題(Question):
想請教為甚麼 a 與 *a 的 %p address 會是一樣的呢?
我的理解是 int (*a)[6] 是指向一個長度為 6 的 int 型態的指標,所以 a 應該會存放
&str 位置
printf a 會出現 &str 這部分可以理解。
但 printf *a 應該是對 a 取值再用%p顯示,所以會得到 0x68 也就是 'h'。
還請各位大神指導,感謝!
雖然這種方式好像很少使用XD
餵入的資料(Input):
NA
預期的正確結果(Expected Output):
run:
a address: 0x7ffdd628c6d2
*a address: 0x7ffdd628c6d2
expect:
a: 0x7ffdd628c6d2
*a: 0x68
錯誤結果(Wrong Output):
NA
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
char str[6] = "hello";
char (*a)[6] = &str;
printf("a address: %p\n", a);
printf("*a address: %p\n", *a);
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.68.47.157 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1685287138.A.E9D.html
推
→
→
→
推
→
推
推
→
→
推
→
→
推
推
→
→
推
推
→
→
→
推
推
→
→
→
推
→
推
推
→
推
推