How a reference to an object is implemented? With the reference a locally declared object can be accessed from another called function. How this is implemented without
passing the address of the object?
Who is Participating?
Answers2000Connect With a Mentor Commented:
If you mean - how does it work internally : The machine code generated by the compiler uses the address of the object.  The important part is the C++ programmer isn't aware that there is address manipulation going on.

On most compilers these 2 functions will generate identical machine code

void SomeFunc1( int& x ) // reference
x = 1 ; // modify reference

void SomeFunc2( int * x ) // pointer
*x = 1 ;

You call these :-

int a ;
SomeFunc1(x) ; // reference call

int b ;
SomeFunc2(&b) ; // pointer call
Answers2000 is right. When a reference to an object is passed as an argument to a function, in reality the address of the object is passed.

leena_maryAuthor Commented:
Here are your points Answers2000.
Thank u pagladasu for your comment.

All Courses

From novice to tech pro — start learning today.