In this article its says that references allow you to reduce the amount of copying behind the scenes. Does reference reduce any other operation compared to a variable?
Share
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.
Reference is a kind of a variable. You’re asking about passing by reference instead of passing by value.
Passing by value creates a copy of the value being passed, while passing by reference means that the receiver will be able to change that same variable whose value you passed.
Both have its own benefits and shortcomings, and should be used when appropriate (for example, by reference would be used sometimes to save on copy operations or get return values, while by value would be used to pass data which shouldn’t be locally changed but will be changed inside the called function).