Question: Program functions work much like mathematical functions. Program functions allow you to define a bit of code which is executed whenever you want. This bit

Program functions work much like mathematical functions. Program functions allow you to define a bit of code which is executed whenever you want. This bit of code is known as the function body. Additionally, program functions can be given parameters, which allow you to pass different values to program functions. For example, consider the following code:
define function f(x)= x +1
y := f(7)
The first line defines a function named f, which takes a single parameter bound to the variable x. The f function will then add 1 to the parameter, and ultimately return the result. The second line then calls function f with parameter 7, yielding the value 8(i.e.,7+1). The value 8 is then reassigned into program variable y.
Function calls can be seen as a way of copying the function body to wherever the call is made, substituting the function parameter in the function definition with whatever parameter is passed in the call. In other words, when f(7) is seen above, this can be replaced with the function body x +1. The x is then substituted with 7, so f(7) overall does the same thing as 7+1.
Consider the code below:
define function f(x)= x * x
y := f(3)
What value will program variable y hold when the above code completes?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!