c - Copying object via pointer and address -


let's have pointer structure, tm:

time_t timestamp = time(null); tm* = localtime(&timestamp); 

to create pointer copy in automatic memory, copy value can used:

tm copy = *now; tm* next = © // next points copy in memory 

but why shortcut doesn't copy value new memory block? (gcc compiler)

tm* next = &(*now); // next points address of 

this may sound trivial i'm not sure mechanism behind. why there difference?

= copying data 1 memory location another. & gives address of variable. * dereferences variable. none of these allocate memory in form, or create temporary variables.

all memory allocations must explicitly stated in c. there no difference found here.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -