What is Return by Reference in C++
What is Return by Reference in C++ In C++ Programming, not only can you pass values by reference to a function but you can also return a value by reference. To understand this feature, you should have the knowledge of: Global variables Example: Return by Reference #include <iostream> using namespace std ; // Global variable int num ; // Function declaration int & test (); int main () { test () = 5 ; cout << num ; return 0 ; } int & test () { return num ; } Output 5 In program above, the return type of function test() is int& . Hence, this function returns a reference of the variable num . The return statement is return num; . Unlike return by value, this statement doesn't return value of num , instead it returns the variable itself (address). So, when the variable is returned, it can be assigned a value as done in ...