If we have this code:
int foo=100;
int& reference = foo;
int* pointer = &reference;
There's no actual binary difference in the reference's data and the pointer's data. (they both contain the location in memory of foo
)
part 2
So where do all the other differences between pointers and references (discussed here) come in? Does the compiler enforce them or are they actually different types of variables on the assemebly level? In other words, do the following produce the same assembly language?
foo=100;
int& reference=foo;
reference=5;
foo=100;
int* pointer=&foo;
*pointer=5;
See Question&Answers more detail:os