[問題] 很基本的pointer用法(K&R page 101)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
gcc 4.4.3 on ubuntu linux
tcc 0.9.24
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
none
問題(Question):
書上的範例過不了編譯 (p.101)
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
t.c:3: warning: data definition has no type or storage class
t.c:3: error: conflicting types for ‘ip’
t.c:2: note: previous declaration of ‘ip’ was here
t.c:3: warning: initialization makes integer from pointer without a cast
程式碼(Code):(請善用置底文網頁, 記得排版)
int x=1;
int *ip;
ip = &x;
補充說明(Supplement):
如果把ip宣告成int,就有拿到x的位置
int x=1, ip;
ip =(int) &x;
不知到是怎麼了,問了一個學過C的同學,他說看不出問題
明明是很簡單的一段code啊
剛開始玩玩看C, 如果問題很蠢的話... 我也不知到該怎麼辦XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.245.32
※ 編輯: kdjf 來自: 140.112.245.32 (03/23 20:14)
→
03/23 20:20, , 1F
03/23 20:20, 1F
→
03/23 20:20, , 2F
03/23 20:20, 2F
→
03/23 20:31, , 3F
03/23 20:31, 3F
→
03/23 20:32, , 4F
03/23 20:32, 4F
→
03/23 20:32, , 5F
03/23 20:32, 5F
※ 編輯: kdjf 來自: 140.112.245.32 (03/23 20:34)
→
03/23 20:35, , 6F
03/23 20:35, 6F
→
03/23 20:38, , 7F
03/23 20:38, 7F
推
03/23 20:45, , 8F
03/23 20:45, 8F
→
03/23 21:18, , 9F
03/23 21:18, 9F
→
03/23 21:19, , 10F
03/23 21:19, 10F
→
03/23 21:33, , 11F
03/23 21:33, 11F
→
03/23 21:35, , 12F
03/23 21:35, 12F
→
03/23 21:35, , 13F
03/23 21:35, 13F
→
03/23 22:04, , 14F
03/23 22:04, 14F