Let's have some pointer to a structure, like tm
:
time_t timestamp = time(NULL);
tm* now = localtime(×tamp);
To create a pointer to a copy in automatic memory, copy by value can be used:
tm copy = *now;
tm* next = ©
// next points to a copy in memory
But why this shortcut doesn't copy the value to a new memory block? (gcc compiler)
tm* next = &(*now);
// next points to the address of now
This may sound trivial but I'm not sure about the mechanism behind. Why is there a difference?