Functions with pass by reference
Learn C++ in step-by-step lessons.
Functions with pass by reference
Pass by reference means that instead of passing the value of a variable to a function, we pass the address of the variable as an argument. When a function receives the address of a variable it can change the value stored at that address.
Pass by reference is usually only used if we need to change the value of a variable.
Goals:
- Use reference variables that are passed to a function
Objectives:
- Be able to explain the use of pass by reference
- Be able to trace a program that uses pass by reference
- Confirm that the argument list matches the parameter list
Please study the material at each of the links below.
Addresses of variables- Finding half the value
- Finding half the value explicitly
- Arguments must match
- Exchanging two values
Glossary for passbyref lessonFull Glossary