I want to pass a value by reference in C. Are this two functions the same? Which is the difference? Is the same in C++?
void foo1(int * val1, int * val2)
void foo2(int &val1, int &val2)
Thanks,
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
References are C++ only (not C).
The implementations of the methods will be different, since dereferencing a reference is different from dereferencing a pointer in C++.
e.g.
vs.
In both cases you’re calling on the original object passed to the method, not a copy.