-1

In below code snippet , while using & with reference variable , we are getting the address of the variable to which the reference variable points but during a function call , the reference variable would have been allocated on the stack frame , so how to get that address value ?

#include <iostream>
using namespace std;
void modify(int& x)
{
    x=9;
    cout<<&x<<endl<<x<<endl;
}
int main() {

    int a=8;
    modify(a);
cout<<&a<<endl<<a;  
    return 0;
}

Here both &x and &a print same value , which is the address of the variable a , so is there any way by which we can get the address of the reference variable x ?

radha
  • 5
  • 2

1 Answers1

6

There is no such thing.

A reference is a synonym. It's a different name for the same object. A name does not have an address. It's just an idea.

Richard Hodges
  • 68,278
  • 7
  • 90
  • 142