How is a reference represented internally and how does it differ from a pointer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • himanigarg
    New Member
    • Oct 2007
    • 7

    How is a reference represented internally and how does it differ from a pointer

    what is internal represtation of reference variable
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    A pointer.

    Except in this case the pointer is managed by the compiler so there won't be any mistakes made.

    The original variable is inbthe stack frame of the calling function. The reference is a pointer in the called functions stack fram back to the original variable. Code is generated to do the address-of on the call and the de-reference as necessary in the called function.

    Since this is a generated pointer, you can't change it to point to something else hence the restriction that you can't change the reference once it's established.

    Comment

    • himanigarg
      New Member
      • Oct 2007
      • 7

      #3
      problem in reference

      what is the use of reference variable when the same work is done using address of (&) and dereference(*) operator

      Comment

      • himanigarg
        New Member
        • Oct 2007
        • 7

        #4
        query of reference

        can u show me with help of diagram internal represntation of reference variable?

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Please do not double post questions and keep all related question about a single topic in a single thread.

          Please read the Posting Guidelines .

          Banfa
          Administrator

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Originally posted by himanigarg
            what is the use of reference variable when the same work is done using address of (&) and dereference(*) operator
            Because you make mistakes using & and * and the compiler doesn't.

            Originally posted by himanigarg
            can u show me with help of diagram internal represntation of reference variable?
            Did not not read post #2??? It's a pointer managed by the compiler.

            Comment

            Working...