2007-03-30

Pointer sequence #2


1 #include
2
3 using namespace std;
4
5 int main()
6 {
7 int a = 1, b = 2;
8 int *x;
9
10 cout << "x: " << x << '\t';
11 cout << "*x: " << *x << '\t';
12 cout << "&x: " << &x << '\t';
13
14 cout << endl;
15
16 x = &a;
17 cout << "x = &a" << '\t';
18 cout << "x: " << x << '\t';
19 cout << "*x: " << *x << '\t';
20 cout << "&x: " << &x << '\t';
21
22 cout << endl;
23
24 x = &b;
25 cout << "x = &b" << '\t';
26 cout << "x: " << x << '\t';
27 cout << "*x: " << *x << '\t';
28 cout << "&x: " << &x << '\t';
29
30 cout << endl;
31 return 0;
32 }



g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


x: 0xb7f078dc *x: -1 &x: 0xbff350c4
x = &a x: 0xbff350cc *x: 1 &x: 0xbff350c4
x = &b x: 0xbff350c8 *x: 2 &x: 0xbff350c4




Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


跑到 line 10 就結束!

then modified code.
x = &a x: 0012FF7C *x: 1 &x: 0012FF74
x = &b x: 0012FF78 *x: 2 &x: 0012FF74

沒有留言: