If I am not mistaken, ASLR will make the local variables in C compilers have a different address each time I run the program. But when I tried it in Turbo C++ and Dev-CPP IDE, it just returns a similar address for local variables. The code i tried:
#include <stdio.h>
#include <conio.h>
int main()
{
int x = 10;
int *ptr = &x;
printf("%d", ptr);
getch();
return 0;
}
Before, I thought the address of the local variables are the same because it is allocated in the same stack area and thus the same memory address. But when i found a thread here in stackoverflow about ASLR, it made me did these. I guess this is because of the compilers. Can anyone shed a light on this?
Edit:
Im using Windows 7.
%d
to print pointers.%d
is only ever suited for printingint
s. Use%p
and an explicit cast tovoid *
instead:printf("%p", (void *)ptr);
- The Paramagnetic Croissant%d
is undefined behavior. - The Paramagnetic Croissant