Why is a c++ reference considered safer than a pointer?

Posted by anand.arumug on Stack Overflow See other posts from Stack Overflow or by anand.arumug
Published on 2011-01-17T17:00:10Z Indexed on 2011/01/17 18:53 UTC
Read the original article Hit count: 242

Filed under:
|
|

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

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;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about pointers