dimanche 25 novembre 2018

How does the call stack look when you initialize a reference from a function return value in C++?

How does the call stack look you initialize a reference with a function return value?

int i = 0;
int &j = i;

I understand that j and i are both pointing to the same memory location.

But when you initialize a reference with a function return value like,

int f();
const int &j = f();

On which stack frame does the memory location referred by j reside? Why does it have to be a const?

Aucun commentaire:

Enregistrer un commentaire