What is a reference exactly?

Hi.

I know about when you should use references and why you use it etc. .
But what is a reference in the memory. I sometimes like to think that a reference
is a constant pointer that cannot be re-assigned. But do references contain the address to a variable like pointers do? Or do references contains something else?
If references also contain addresses like pointers, then why are there references in the first place when you can just use constant pointers?

closed account (N36fSL3A)
Because it's stupid to treat all variables as pointers.

References are mainly used to change values within functions, as they just reference the memory location of the variable.
But do references contain an address like pointers do? How do they refer to the variable?
closed account (z05DSL3A)
Zerpent wrote:
But what is a reference in the memory.
It doesn't have to be anything. There is no definite storage associated with a reference.
Ok, I see. Thanks for your answers.
closed account (z05DSL3A)
But do references contain an address like pointers do? How do they refer to the variable?
A reference is just another name for an object, it is probably not worth thinking of a reference as an object.
not only not worth, it would actually be wrong to: references are not objects by definition (and that is why they don't have a size and can't be placed in arrays, among other things).
Topic archived. No new replies allowed.