Reputation: 41
It's not really a problem for me but I just started thinking about it and I thought I'd ask. Why would that return different values each time I run the program (0x3759F8B0 - 0x100)?
One time it says 00AFFD00 and the next it says 006FFD48
test = 0x3759F8B0 - 0x100;
cout << &test << endl;
Upvotes: 3
Views: 87
Reputation: 162194
I suppose your full program source reads as
#include <iostream>
using namespace std;
int main()
{
int test;
test = 0x3759F8B0 - 0x100;
cout << &test << endl;
}
As @pat already mentioned in comment, your program emits the address of the variable test
, not its value. On modern operating systems there is something called "address space layout randomization" (ASLR, see https://en.wikipedia.org/wiki/Address_space_layout_randomization for a good overview) which helps making it harder to exploit security vulnerabilities that may exist in a program. The idea is, that with every new start of a program the addresses of the stuff it uses are randomized. Hence the address of variables will change on every launch with ASLR enabled.
ASLR is now a standard feature in mainstream operating systems. However it can be disabled (not recommended) and without ASLR the above program would indeed always emit the same output.
Upvotes: 8