Re: 請教C語言內的指標傳遞

看板Programming作者時間18年前 (2006/10/28 21:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《quota@kkcity.com.tw (我要出清)》之銘言: > 請教一下,我的指標變數之間互相傳遞資料 > 為何以下的方式不行,而得用 sub(p,p);呢? > 我想把*p丟給*x 不能直接丟嗎? > 謝謝 > 附上原始碼如下 > #include <dos.h> > #include <stdlib.h> > main() > { > void sub(int *,int*); > int *p,a=1; > p=&a; > sub(*p,*p); 你可能要弄清楚 dereference operator (* 號) 的意義, 你既然 sub 是接收 type 為 (int *) 的引數, 你對 p 做 dereference 得到的 type 是 int, 這樣當然是錯誤的。 所以直接送 sub(p, p) 就好了。 -- Name: Tseng, Ling-hua E-mail Address: uranus@it.muds.net School: National Tsing Hua University Department: Computer Science Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design Researching: Undecided Homepage: https://it.muds.net/~uranus -- ╔═══╗ ┼────────────────────────╮ 狂狷 Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮ 年少 ┼╮ < IP:140.119.164.252 > ╰─╮ ╚╦═╦╝ From:61-230-224-108.dynamic.hinet.net ─╨─╨─ KGBBS 遨翔"BBS"的狂狷不馴;屬於年少的輕狂色彩
文章代碼(AID): #15GrIG00 (Programming)
文章代碼(AID): #15GrIG00 (Programming)