returning an address in memory

What ways can a function return an address in memory that are acceptable? Which ways are unacceptable?
luoysAsked:
Who is Participating?
 
steveiamCommented:
What language are you using? Is there any more context to your question?  What are you intending to do with the pointer after its returned?

If you're using C/C++, returning an address in memory is what happens when you return a pointer.  Generally, you want to return a pointer to memory that someone "owns", i.e. not unallocated memory.

Because of the way C/C++ works, a lot of things are referred to by pointers, and its fairly unavoidable.  In these cases its normal to pass and return pointers.
0
 
rubentrancosoCommented:
A function can return a pointer to the address. It's acceptaple. A pointer is a integer that maps to a memory location. Anything that can be translatade to a integer is acceptable.
0
 
luoysAuthor Commented:
In C++ besides pointer, I think a function can also return an address in memory by reference. Is that correct? Is there any other way to return an address in memory?
0
 
rubentrancosoCommented:
A pointer IS a address in memory referenced by a integer. If you pass a address of a integer you can cast it to a void pointer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.