CSE 232 SS13 Lab 4 Notes 1. Arguments and Parameters Formal argument -- the name used within a function definition Actual argument -- variable or constant used in a function call Parameter = formal argument Argument = short for "actual argument" 2. Value and Reference paramters A.k.a. "pass by value" and "pass by reference". Value parameters are *copies* -- changes to these variables they do not affect the argument, which can be a constant or a variable. Reference parameters (marked with "&") are not copies. The parameter inside the function names the same memory location as the variable that was given as an argument, which must be a variable. /* params.h */ void f(int x); void g(int x); /* params.cpp */ void f(int x) { x = 100; } void g(int & x) { x = 100; } /* driver.cpp */ #include "params.h" int main { int x = 5; f(x); // x is still 5 g(x); // x is now 100 } 3. Uses of Reference Parameters a. Method for multiple return values ex. void f(int & a, int & b, int & c) { ... } b. Most efficient way to pass class objects, since copying large objects takes time