Variables, References, Pointers
Overview
Variables
- are identifiers associated with memory
- must be declared before used
- can be uninitialized
- can be initialized with a value
- can be assigned a value
Variable (basic)
Reference variable
Pointer variable
Parameter Passing
actual parameter = parameter value (argument)
printCard(c1);
formal parameter = parameter variable (parameter)
void printCard(Card c) ...
Java - all parameters are pass-by-value
C++ - has three ways to do parameter passing:
Which way is specified in the function's header (prototype):
Pass-by-value
- formal parameter gets a copy of the actual parameter's value
Pass-by-reference
- formal parameter gets a reference to the actual parameter
Pass-by-const-reference
- formal parameter gets a reference to the actual parameter but the actual parameter cannot be changed by the function