這基本上只是爲了幫助我更好地理解指針,所以如果你們可以確認/否認/解釋任何事情,它看起來像我不明白我會最感激。使用郵箱,阿姨,街道和所有垃圾的例子只是令人困惑。C++指針和引用說明
int a = 5;
int b = &a; // b will be the memory address of 'a'
int *c = a; // c will be the value of 'a' which is 5
int *d = &a; // d will be a pointer to the memory address of 'a'
int &e = a; // what would this be?
void FunctionA()
{
int a = 20;
FunctionB(&a);
// a is now 15?
}
void FunctionB(int *a)
{
a = 15;
}
謝謝大家的幫助,我只是試圖提高我的理解超越所有的蹩腳的比喻解釋即時閱讀。
很好的答案在這裏:http://programmers.stackexchange.com/questions/17898/whats-a -nice-pointers for pointers – 2010-11-16 02:40:26
您是否試圖編譯所有這些語句? – 2010-11-16 02:40:32
把'e'想象成'a'的別名。任何時候讀取'e',都會返回'a'的值。任何時候你寫'e','a'都會更新。 – jalf 2010-11-16 02:55:34