C++ const reference

// Pass by value
// copy object n, any change will change the copy n. (I.e. Origin n will not change.)
void f(int n){} 

// Pass by reference
// use original object n, any change will cause n change.
void f(int& n){}

// Constant reference
// no copy, n read only, can not change value n.
void f(const int& n){} 

Last updated

Was this helpful?