// C5_5.cpp : Defines the entry point for the console application. // 指標變數的使用 #include "stdafx.h" #include using namespace std; int main(int argc, char* argv[]) { long* ptr1 = NULL; // 指標宣告和初始化 long data1 = 166, data2 = 88; ptr1 = &data1; // 將位址存到指標 *ptr1 += 20; // 改變指標所指的內容 cout << "ptr1(位址) = " << ptr1 << endl << "data1(內容) = " << data1 << " &data1(位址) = " << hex << &data1 << endl ; ptr1 = &data2; // 改變指標所指的位址 data1 = *ptr1/10; // 改變指標所指的內容 cout << endl << "data1(內容) = " << dec << data1 << " ptr1(位址) = " << hex << ptr1 << " *ptr1(內容) = " << dec << *ptr1; cout << endl; return 0; }