UMBC CS 201, Spring 02
UMBC CMSC 201 Spring '02 CSEE | 201 | 201 S'02 | lectures | news | help

Hiding Details

Functions can also be used to hide details. What is the point ?
  1. To make our main program simpler and easier to read. For instance, we could call a function named PrintGreeting() and assume that it will do just that. We have now managed to remove many lines of code that just clutter the main program.

    Here is an example:

    /*PrintGreeting prints the greeting for */ /*the program. */ /*Inputs: none Outputs: none (prints to screen)*/ void PrintGreeting( void ) { printf("\n\n"); printf("*************************************\n"); printf("*Hello. *\n"); printf("*This program finds the surface area*\n"); printf("*and volume of a sphere. *\n"); printf("*************************************\n\n"); }

  2. In order for other programmers to make use of functions we've written, it is sufficient for them to know what the function does, what arguments it takes and its return type. They do not need to know how we decided to write the code within the function definition.


CSEE | 201 | 201 S'02 | lectures | news | help

Thursday, 17-Jan-2002 13:52:04 EST