Search This Blog

Friday, June 8, 2012

Functions


Functions


A function is a self-contained block of program that performs a coherent task of some kind. A function provides a convenient way to encapsulate some computation in a black box which can then be used without worrying about its innards.

  •  Every C program can be thought as a collection of functions.
  •  Any C program would contain at least one function
  •  If a C program contains only one function it must be main()
  •  Program execution always begins with main()
  • There is no limit on the numbers of functions that might be present in a C program.
  • main() will usually invoke other functions to perform its job, some coming from the same program and other from libraries of pre-written functions.
  •  Functions can appear in either order and in one source file or two
  •  Not all functions produce an integer value.

Structured Programming


Functions can be used in structured programming: a program discipline in which individual tasks are
performed by independent modules of program code. A specific program module can be a function
definition.


Top Down Design
Functions are really the only way to cope with the potential complexity of large programs. Structured
programming enables programmers to take the advantage of top down design methodology. In this case a
complex programming problem is broken up into a number of much simpler and manageable tasks in a
hierarchical way. Each task can be assigned a function in which program code and variables used are
isolated from the rest of the program.

No comments:

Post a Comment