returning an address in memory

Posted on 2006-05-10
Last Modified: 2008-02-01
What ways can a function return an address in memory that are acceptable? Which ways are unacceptable?
Question by:luoys
    LVL 3

    Accepted Solution

    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.

    Expert Comment

    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.

    Author Comment

    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?

    Expert Comment

    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

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    has77  challenge 9 56
    method argument as final 1 54
    scoresAverage challenge 8 58
    mapShare challenge 13 40
    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now