Pointers vs. References in Parameter Passing
Regarding pointers and references as function parameters, the code snippets provided do have functional similarities:
int foo(bar* p) { return p->someInt(); }
and
int foo(bar& r) { return r.someInt(); }
However, there are subtle differences between the two:
In C , references intentionally are not implemented explicitly with pointers. Instead, they serve as "synonyms" for the referenced variable. This concept enables compiler optimizations where pointers would be unnecessary.
Other notable differences between pointers and references include:
The above is the detailed content of Pointers vs. References: When to Use Each in Function Parameters?. For more information, please follow other related articles on the PHP Chinese website!