Previous: 3.6 Common Errors
Up: 3 Designing Programs Top Down
Next: 3.8 Exercises
Previous Page: 3.6 Common Errors
Next Page: 3.8 Exercises
This chapter has presented a key concept in the design of good programs; namely, top down design. Beginning with the algorithm, complex programming tasks are divided into logical subtasks which themselves may be further divided. This structured design is a form of information hiding - hiding the details of an operation in its abstraction. We have described how these logical subtasks may be implemented using functions in C. A function is a block of code, which when given some information, performs some operations on the data and returns a value. To invoke (call) a function, use a statement with the form:
We saw that the <parameter>'s in the function header are really just special forms of variable declarations; containing a type specifier and an identifier. They declare additional local variables within the function which are initialized to the values passed as arguments in the call. We also saw how declaration statements can initialize variables when a block is entered:
The value returned by a function is specified in a return statement of the form:
Next we discussed another form of information hiding using compiler directives processed by the C preprocessor. These included macros, with and without arguments, including header files, and conditional compilation.
Finally, we described the relationship between I/O in C and files, including end of file and redirection of standard input and output files.