Function and Recursion

A function is a grouping of statements that are created to do a particular job. Modules are required when a group of statements are frequently used by other distinct code. These are called Sub-Program.
Together, they referred to as Modular Programming.
Advantages:

  • An easily comprehensible top-down design
  • Can be done by more than one developers
  • Easy to debug
  • Modifications can be done without affecting the overall code
  • Easier to document
Functions are divided into two types:

  • Library function, a standard function provided by the code compiler
  • User-defined function, a self defined function
In addition to Function, there are also Identifiers. There are two types:

  • Local Identifier, which are declared in the function and are limited to the functions
  • Global Identifier, which are declared outside the function, can be re-declared in the function, and can be reached from anywhere in the program
Do note, however, that it is advisable not to use Global Variable for a number of reasons:

  • Error rates increase
  • Difficult to debug
  • Low Data Exclusivity
If a module is not self-sufficient then the data and its result use parameters to pass through. these passing parameters are the interface of modules to other modules.
They are divided into two types:

  • By-Value Parameters, that send value to other modules
  • By-Location Parameters, that send address to other modules
A recursive is a function call inside a certain function calling itself. They are made up of two components:

  • Base Case, which is the return value
  • Reduction Step, a series of input converging on the base case
Despite recursive code being rather concise, it needs:

  • More memory consumption
  • Takes longer time

Comments

Popular posts from this blog

Sorting & Searching

Pointer and Array in C Programming Language