2007-03-30

Pointer sequence #1


#include

using namespace std;

int main()
{
int a, b, c, d, e;
int i;

cout << "Input five numbers: \n";
cin >> a >> b >> c >> d >> e;
cout << "A: " << &a << "\nB: " << &b
<< "\nC: " << &c << "\nD: " << &d << "\nE: " << &e;

cout << endl;
return 0;
}



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


1
2
3
4
5
A: 0012FF7C
B: 0012FF78
C: 0012FF74
D: 0012FF70
E: 0012FF6C


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


1
2
3
4
5
A: 0xbfdc2cec
B: 0xbfdc2ce8
C: 0xbfdc2ce4
D: 0xbfdc2ce0
E: 0xbfdc2cdc




#include

using namespace std;

int main()
{

cout << "Input five numbers: \n";
cin >> a >> b >> c >> d >> e;
for (i = 0; i < 5; i++)
cout << "Var" << i << ":\t"
<< &a - i << " : "
<< *(&a - i) << '\n';

cout << endl;
return 0;
}


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


1
2
3
4
5
Var0: 0012FF7C : 1
Var1: 0012FF78 : 2
Var2: 0012FF74 : 3
Var3: 0012FF70 : 4
Var4: 0012FF6C : 5


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


1
2
3
4
5
Var0: 0xbfdea9e0 : 1
Var1: 0xbfdea9dc : 2
Var2: 0xbfdea9d8 : 3
Var3: 0xbfdea9d4 : 4
Var4: 0xbfdea9d0 : 5

沒有留言: