看板Programming
标 题Re: 请教C语言内的指标传递
发信站政大狂狷年少 (Sat Oct 28 20:42:48 2006)
转信站ptt!ctu-reader!ctu-peer!news.nctu!news.cis.nctu!news.cs.nthu!WHSHS
※ 引述《[email protected] (我要出清)》之铭言:
> 请教一下,我的指标变数之间互相传递资料
> 为何以下的方式不行,而得用 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:
[email protected]
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"的狂狷不驯;属於年少的轻狂色彩 ◎