Functions
In general, you use a function in an expression by writing the function name followed by the arguments, in parentheses. The parentheses are required. Each argument can be any expression. For example, the value of expression sqrt(9.0 + 16.0) is approximately 5.0. If there are two or more arguments, separate them by commas. For example, expression pow(2+3, 4/2) has value 25.0. |
Evaluating expressions
Evaluate an expression from the inside out. For example, if f (x) = x + 1, then expression f (3+2) + 1 has value 7, computed as follows.
and
|
Terminology: calling a function
An expression that uses a function is referred to as a function call, and we say that expression sqrt(2.0) calls sqrt. |
Nested function calls
The argument of a function can be any expression, including an expression that uses a function. For example, if f (x) = x + 1, then
and if g(x) = 2*x + 4, then
|
Arguments/parameters
If E is an expression and f is a function, then we say that E is the argument of f in expression f (E). I will use term parameter interchangeably with argument. |
Suppose that g(x) = 3x − 2. What is the value of expression g(g(9) + 1)? Answer
Suppose that g(x) = 3x − 2. What is the value of expression g(g(9 + 1))? Answer
Suppose that g(x) = 3x − 2. What is the value of expression g(g(9)) + 1? Answer