#include #include using namespace std; int main() { char ch='z'; char ch_arr[10]="abcd"; char *pch; int a=10, b=20; int *p1, *p2; int sub1, sub2; float c=30.0; float *ptrf; /* 設定運算 */ p1 = &a; /* 將a的位址存放於p1 */ p2 = &b; /* 將b的位址存放於p2 */ pch = &ch; /* 將ch的位址存放於pch */ ptrf = &c; cout << "addr. of a、p1 : " << p1 << " 、 " << &p1 << endl; cout << "sizeof(a) : " << sizeof(a) << endl; cout << "sizeof(p1) : " << sizeof(p1) << endl; cout << "sizeof(*p1) : " << sizeof(*p1) << endl << endl; cout << "addr. of b、p2 : " << p2 << " 、 " << &p2 << endl; cout << "sizeof(b) : " << sizeof(b) << endl; cout << "sizeof(p2) : " << sizeof(p2) << endl << endl; cout << "addr. of c、ptrf : " << ptrf << " 、 " << &ptrf << endl; cout << "sizeof(c) : " << sizeof(c) << endl; cout << "sizeof(ptrf) : " << sizeof(ptrf) << endl << endl; //這行的字元變數位址取不到 cout << "addr. of ch、pch: " << &ch << " 、 " << &pch << endl; cout << "sizeof(ch) : " << sizeof(ch) << endl; cout << "sizeof(pch) : " << sizeof(pch) << endl << endl; cout << "addr. of ch_arr : " << &ch_arr << endl; cout << "addr. of ch_arr + 1 : " << *ch_arr+1 << endl; cout << "addr. of ch_arr + 2 : " << *ch_arr+2 << endl; /* 差值運算*/ sub1 = p1 - p2; /* 計算p1和p2相差距離 */ sub2 = *p1 - *p2; /* 計算p1所指變數a和p2所指變數b的差 */ cout << endl << "=======================" << endl; cout << "sub1 = " << sub1 << endl; cout << "sub2 = " << sub2 << endl; cout << endl << "=======================" << endl; cout << "Before process ... " << endl; cout << "addr. of p1 : " << p1 << endl; cout << "addr. of p2 : " << p2 << endl; //這行的字元變數位址取不到 cout << "addr. of pch : " << pch << endl; /* 加減法運算 */ p1++; /* 將p1所存整數a位址加上整數型態長度4bytes */ p2--; /* 將p2所存整數b位址減去整數型態長度4bytes */ pch++; /* 將pch所存字元ch位址加上字元型態長度1byte */ cout << endl << "=======================" << endl; cout << "After process ... " << endl; cout << "addr. of p1 : " << p1 << endl; cout << "addr. of p2 : " << p2 << endl; //這行的字元變數位址取不到 cout << "addr. of pch : " << pch << endl; system("pause"); return 0; }