How does a reference work?

I’m a bit confused on how references actually work.
Let’s say I have this:

int i = 17;
int& r = i;

If I understand correctly, variables don’t interact with their memory/address, they only get the value that has been assigned to them.

So … do references first access the address of the variable and consequently the value?

OR does the reference first access the variable and then the value?

Thanks,
Enrico

They’re implemented as pointers, there’s no such thing as references at the hardware level. So you can think of it as a pointer that’s always dereferenced when accessed.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.