c++ - Assigning a value to a pointer -


if have following example:

int *x; x = func(a); 

for statement: x = func(a);, returning address x? or, how read it?

edit: is eligible returning pointer x? if so, can explain how done exactly? mean, how returning pointer?

x pointer, int. should obvious there 2 memory locations used. 1 pointer , 1 memory it's pointing (assuming pointer not null).

the pointer holds memory address, location of memory it's pointing to. 0xa456e4fa.

yes, func() returning pointer. prototype of func following..

int * func(someobj a); //i don't know datatype of parameter,                        //so i'm making up. 

notice return type pointer int. , said previously, should obvious return. of form 0xyyyyyy, or memory address/pointer. memory address goes x pointer.

remember pointer not holding data it's pointing to, address. there's no reason can't return pointer. however, need careful in return. not want return address of local variable because variable go out of scope once function has completed execution. you'll returning address of invalid. returning value of local pointer however, fine because value returned (the address) preserved memory it's pointing to.

i realized wrote book. damn, sure ramble when i'm tired.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -