returning an address in memory

What ways can a function return an address in memory that are acceptable? Which ways are unacceptable?
Who is Participating?
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.
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.
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?
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
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.