Demonstrate the use of C user-defined functions with a suitable example.

7. A) Demonstrate the use of C user-defined functions with a suitable example.

Answer:-

User-defined functions are written by programmers to serve their own purpose and are
not readily available.

Functions based modular programming is advantageous in many ways:

  1. Managing huge programs and software packages is easier by dividing them into functions/modules—Maintenance is easier
  2. Error detection is easier—Debugging is easier
  3. Functions once written can be reused in any other applications – Reusability is enhanced
  4. We can protect our data from illegal users—Data protection becomes easier
Figure 1: Top-down modular programming using functions

Following block diagram explains how functions are useful:Instead of writing entire program (to add and subtract) within main( ) function we can write independent modules add( ) and subtract( ) as shown:

Leave a Reply

Your email address will not be published. Required fields are marked *