看板Programming
标 题Re: 请问 指标~~
发信站政大狂狷年少 (Sat Oct 14 21:03:21 2006)
转信站ptt!ctu-reader!ctu-peer!news.nctu!news.cis.nctu!news.cs.nthu!WHSHS
※ 引述《[email protected] (... (b) pic)》之铭言:
> int *ptr ;
> cout<<ptr ;
> cout<<&ptr;
> 请问这两种输出位址值差在那里 ??
> 那
> cin>>n ;
> int *ptr= new int[n] ;
> cout<<ptr ;
> cout<<&ptr ;
> 这两种输出又分别指向那一个位址值ㄋ ?
> 谢谢各位大大 ^^" 有点被指标搞混了
pointer 本身也是 variable,
只是多了 dereference operator (*) 可以用,
而 variable 都可以用 address-of operator (&) 取出 lvalue,
cout << ptr 当然输出的是 ptr 的 rvalue,
而 cout << &ptr 输出的当然就是 ptr 的 lvalue。
道理跟一般 variable 是完全相同的。
--
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-221-119.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不驯;属於年少的轻狂色彩 ◎