cout << "The address of a is " << &a << endl << "The value of aPtr is " << aPtr << endl << endl; cout << "The value of a is " << a << endl << "The value of *aPtr is " << *aPtr << endl << "The address of aPtr is " << &aPtr << endl << endl; cout << "Showing that * and & are inverses of each other" << endl << "&*aPtr = " << &*aPtr << endl << "*&aPtr = " << *&aPtr << endl;
return0; }
宣告一個整數 a 和整數指標 aPtr,將其指向 a,接著印出其數值和記憶體位置。 編譯執行之後,輸出的會是什麼呢?
1 2 3 4 5 6 7 8 9 10
The address of a is 0x7ffeed8f6928 The value of aPtr is 0x7ffeed8f6928
The value of a is 7 The value of *aPtr is 7 The address of aPtr is 0x7ffeed8f6920
Showing that * and & are inverses of each other &*aPtr = 0x7ffeed8f6928 *&aPtr = 0x7ffeed8f6928