@DaemonR: Thank you.
But this will again involve pointers(which are apparent to programmers) and will have their own memory address whereas in C++ reference variables variable and its alias share the same memory address(Correct me if I'm wrong).
dansmahajan wrote:@DaemonR: Thank you.
But this will again involve pointers(which are apparent to programmers) and will have their own memory address whereas in C++ reference variables variable and its alias share the same memory address(Correct me if I'm wrong).
Except for the fact that in C the caller would do "foo(&bar);" (which makes it obvious that bar may be modified), and in C++ the caller does "foo(bar);" where it looks like the variable is passed by value and safe from modification when it's not.
This is what makes it "syntactical sugar poured into your gas tank".
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Brendan wrote:Except for the fact that in C the caller would do "foo(&bar);" (which makes it obvious that bar may be modified), and in C++ the caller does "foo(bar);" where it looks like the variable is passed by value and safe from modification when it's not.
Agree, therefore I still pass by pointer when the value would be modified, although this means adding an extra a null check.
Pass by reference is still useful when it's const: