A
aistone
Hi all,
If I compile the following program with G++ 4.0.2 and run it I get the
following output:
#include <iostream>
using namespace std;
int main(char argc, char *argv[]) {
int x, y;
cout << "Address of x = " << (unsigned long)&x << endl;
cout << "Address of y = " << (unsigned long)&y << endl;
cout << "Difference in addresses = "
<< (unsigned long)&y - (unsigned long)&x << endl;
return 1;
}
$ ./a.out
Address of x = 3219613408
Address of y = 3219613404
Difference in addresses = 4294967292
I'm wondering why does "Difference in addresses" show a long, seemingly
random, number instead of 4? Am I casting things wrong?
Thanks,
-Andy
If I compile the following program with G++ 4.0.2 and run it I get the
following output:
#include <iostream>
using namespace std;
int main(char argc, char *argv[]) {
int x, y;
cout << "Address of x = " << (unsigned long)&x << endl;
cout << "Address of y = " << (unsigned long)&y << endl;
cout << "Difference in addresses = "
<< (unsigned long)&y - (unsigned long)&x << endl;
return 1;
}
$ ./a.out
Address of x = 3219613408
Address of y = 3219613404
Difference in addresses = 4294967292
I'm wondering why does "Difference in addresses" show a long, seemingly
random, number instead of 4? Am I casting things wrong?
Thanks,
-Andy