Uses of Functions
- In the previous program, power is a function.
It takes two arguments, x and n, and returns a
value, x ^ n . That's what functions do: they take values
(their inputs), and produce outputs (their return value) which
other functions (including main) can use.
- The uses of functions are legion.
- Functions provide a black box abstraction where details
can be hiden.
- Functions enable top down programming, the successive
breaking down of a complex task into simpler ones.
- Functions promote code re-use.
- Functions allow you to, in effect, add new words to the C language.
By building up your own library of useful functions, you can
(approximately) create your own language.
Next Slide