IV Variable Scope and Structuring Code

Chapter 13
Introduction to C Functions
You can take advantage of your computer's repetitive nature by looking at your programs in a new way as a series of small routines that execute whenever you need them, however many times you require. This chapter approaches its subject a little differently from previous chapters. It concentrates on teaching the need for writing your own functions, which are modules of code that you execute and control from the main() function. So far, all programs in this book have consisted of a single long function called main(). As you learn here, the main() function's primary purpose is to control the execution of other functions that follow it.
This chapter stresses the use of structured programming, sometimes called modular programming. C was designed to make it easy to write your programs in several modules instead of as one long program. By breaking the program into several smaller routines (functions), you can isolate problems, write correct programs faster, and produce programs that are easier to maintain.
This chapter teaches you the following topics:
The need for functions
How to trace functions
How to write functions
How to call and return from functions

 



C by Example
C by Example
ISBN: 0789722399
EAN: 2147483647
Year: 1999
Pages: 43
Authors: Greg Perry

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net