Syntax
void setToZero(int value)
{
value = 0;
}
int number { 5 };
setToZero(number);
// number is still 5
The parameter is a separate object initialized from the argument. Changing the parameter does not change the caller’s variable.
When to use it
- Small and inexpensive types such as
int,double, andchar - Values the function needs to store or modify independently
- Cases where copying is intentional