Why does this code give two different memory addresses?
I was just looking at this code and I can't explain why it's working in this way. I would expect the value given by &x and ptr to be the same, but it doesn't if you compile and run the program.
Code:
int main(int argc, char *argv[])
{
int x=5, *ptr; // x set to 5 for example only
*ptr = x;
printf("%x\n%x\n\n, ptr, &x);
free(ptr);
return 0;
}
I can't understand why they give different addresses, but for some reason, they do. I would be grateful if someone could explain to me why this is the case.