Re: [問題] 簡單指標釐清
First of all, you should use %p to print a pointer.
Second, yes, you're printing a, which is a "pointer" and it has been set to 3.
It does not mean you set the integer to 3; rather, you set the "pointer" to 3.
不好意思
請問我可以理解成有一個記憶體位址為0x3
而我把int *a = 3;是在直接對a指派他要指的位址一樣
就像是在做int *a; a = 2200FF;之類的事情嗎?
那麼如果是這樣的話
建議的寫法,是int b=3; int *a; a = &b;
會比較嚴謹嗎??
謝謝
It seems to be correct is simply because you're using int.
Try other incompatible data type like double or string,
your compiler will not allow you to do that any more.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.33.84
→
10/10 19:56, , 1F
10/10 19:56, 1F
推
10/10 19:59, , 2F
10/10 19:59, 2F
→
10/10 19:59, , 3F
10/10 19:59, 3F
→
10/10 19:59, , 4F
10/10 19:59, 4F
推
10/10 20:04, , 5F
10/10 20:04, 5F
→
10/10 20:04, , 6F
10/10 20:04, 6F
→
10/10 20:05, , 7F
10/10 20:05, 7F
夭壽~謝謝大家
我突然整個開竅了
我懂了!!我想了一下我到底需要的是什麼
結果發現我把問題複雜化了
不過我現在只是想知道
int *a = 3;這樣子宣告的compiler詳細動作
以便更了解
謝謝各位的指點
※ 編輯: mgupo 來自: 123.195.33.84 (10/10 20:12)
→
10/10 20:11, , 8F
10/10 20:11, 8F
→
10/10 20:11, , 9F
10/10 20:11, 9F
→
10/10 20:12, , 10F
10/10 20:12, 10F
→
10/10 20:13, , 11F
10/10 20:13, 11F
→
10/10 20:14, , 12F
10/10 20:14, 12F
→
10/10 20:21, , 13F
10/10 20:21, 13F
→
10/10 20:23, , 14F
10/10 20:23, 14F
推
10/10 20:26, , 15F
10/10 20:26, 15F
→
10/10 20:29, , 16F
10/10 20:29, 16F
→
10/10 20:30, , 17F
10/10 20:30, 17F
→
10/10 20:30, , 18F
10/10 20:30, 18F
→
10/10 20:33, , 19F
10/10 20:33, 19F
→
10/10 20:33, , 20F
10/10 20:33, 20F
→
10/10 20:34, , 21F
10/10 20:34, 21F
→
10/10 20:34, , 22F
10/10 20:34, 22F
→
10/10 20:42, , 23F
10/10 20:42, 23F
→
10/10 20:43, , 24F
10/10 20:43, 24F
→
10/10 23:37, , 25F
10/10 23:37, 25F
→
10/10 23:38, , 26F
10/10 23:38, 26F
→
10/10 23:38, , 27F
10/10 23:38, 27F
→
10/10 23:53, , 28F
10/10 23:53, 28F
→
10/10 23:56, , 29F
10/10 23:56, 29F
→
10/11 00:00, , 30F
10/11 00:00, 30F
推
10/11 00:06, , 31F
10/11 00:06, 31F
→
10/11 00:12, , 32F
10/11 00:12, 32F
推
10/11 00:18, , 33F
10/11 00:18, 33F
→
10/11 00:21, , 34F
10/11 00:21, 34F
→
10/11 00:21, , 35F
10/11 00:21, 35F
→
10/11 00:22, , 36F
10/11 00:22, 36F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章