Why is a c++ reference considered safer than a pointer?
- by anand.arumug
When the c++ compiler generates very similar assembler code for a reference and pointer, why is using references preferred (and considered safer) compared to pointers?
I did see
Difference between pointer variable and reference variable in C++ which discusses the differences between them.
EDIT-1:
I was looking at the assembler code generated by g++ for this small program:
int main(int argc, char* argv[])
{
int a;
int &ra = a;
int *pa = &a;
}