Reference Parameters
References Reference variable Alias / shortcut to another variable Declared with Type& Name
References References do not have their own value
References Refer to Variables A reference MUST refer to another variable
Reference Parameters Reference parameter indicates pass by reference: Standard is pass by value:
Reference Parameter x is a link back to num
Reference Parameter Uses Another way to get information back from a function:
Reference Parameter Uses Used in some library functions cin.get(char &c) get one char, possibly whitespace
Reference Parameter Uses Way to get multiple pieces of information back from function:
Reference Parameter Efficiency Value parameters require copying parameter What if parameter is huge? Reference parameter does not copy… links Minimal overhead Danger of modification!
Const References A const & can not be modified: Any attempt is compile error:
Function IO Ways to give functions info Global variables I set this random variable for you to read… Parameters Here is the list of things you asked for
Function IO Ways to give functions info Global variables I set this random variable for you to read… Parameters Here is the list of things you asked for
Returning Information Can get information from function with: Global variables I think you set this random variable… Reference Parameters I passed you these things by reference, you may have changed them for me… Return value You always give me back an int…
Returning Information Can get information from function with: Global variables I think you set this random variable… Reference Parameters I passed you these things by reference, you may have changed them for me… Return value You always give me back an int…
When To Reference Function produces 1 output return it Function needs to produce 2+ outputs extra reference parameters for outputs return void
When To Reference Function must modify inputs Are you sure??? If so use refs: Function needs to work with large data item: const refs