April 2024
Beginner to intermediate
500 pages
24h 20m
English
We have used functions to implement abstraction. We have broken problems down into smaller, more manageable pieces and have implemented functions that we can call again and again. In the previous section, we pushed this idea one step further by passing functions as parameters to other functions. In this section, we explore in more detail the underlying mechanics of functions and parameter passing.
Consider the function shown in Listing 6.7, which computes the hypotenuse of a right triangle. Using the Pythagorean theorem, a2 + b2 = c2, this function takes in the lengths of the two shorter sides, a and b, and computes and returns the length of the long side, c. In the function definition, the parameters ...
Read now
Unlock full access