Re: 請教C語言內的指標傳遞
※ 引述《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"的狂狷不馴;屬於年少的輕狂色彩 ◎
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章