Programming for Kids - ZedLX

The Easiest Way to Learn Computer Programming, for Free

Functions [2/9]

The given program defines a function named square. The function square has one parameter, which is named x and it is of type num.

Upon the execution of a function call expression, for example square(5), resulting value of the function call expression is return value of the function. Return value of function square is computed as a result of the expression x*x. Therefore, the expression square(5) evaluates to value 25 (in the same manner as, for example, expression 4+3 evaluates to value 7).

The type of return value is given after the keyword fn. The type of return value is num.

The function square is called four times in this program. In the first call, the argument of function square equals 5, in the second call the argument equals 2, and in the third call it equals 10.

On each call of a function, the values of arguments get assigned to the function's parameters. In the last call of function square, the argument is the expression 3+1. The value 4 of the argument gets assigned to the parameter x.