C++ examples for Data Type:Reference
Pass an address into a function with reference
#include <iostream> using namespace std; void f(int& r) { cout << "r = " << r << endl; cout << "&r = " << &r << endl; r = 5;/*from w w w . j a v a 2 s .c om*/ cout << "r = " << r << endl; } int main() { int x = 47; cout << "x = " << x << endl; cout << "&x = " << &x << endl; f(x); // Looks like pass-by-value, // is actually pass by reference cout << "x = " << x << endl; }