Chapter 06
Chapter 06
• Definition includes
name: name of the function. Function names
follow same rules as variable names
parameter list: variables that hold the values
passed to the function
body: statements that perform the function’s task
return type: data type of the value the function
returns to the part of the program that called it
val num
5 5
argument in parameter in
calling function evenOrOdd function
• Local variables
– Only exist while the function is executing
– Are redefined each time function is called
– Lose their contents when function terminates
• static local variables
– Are defined with key word static
static int counter;
– Are defined and initialized only the first time the
function is executed
– Retain their contents between function calls
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-34
6.12 Default Arguments
int localVar = 5;
squareIt(localVar); // localVar now
// contains 25