Re: 請問 指標~~
※ 引述《junshung@kkcity.com.tw (... (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: 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-221-119.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不馴;屬於年少的輕狂色彩 ◎
討論串 (同標題文章)