Friday, 23 March 2018


A function is a self contained block of statement that perform a coherent task of some kind.
Function provides modularity to the software.

Function definition :
[data type] function name (argument list)
argument declaration;
local variable declaration;
[return expression]

Example :
int a,b;
int y;
y = a + b;
return y;
When the value of y which is the addition of the values of a and b.The last two statement i.e.,
y = a + b; can be combined as
return (y)
return (a + b)

Why Functions are used ?
  1. Many program require that a specific function is repeated many times instead of writing the function code as many timers as it is required we can write it as a single function and access the same function again as many times as it is required.
  2. We can avoid writing redundant program code  of some instructions again and again.
  3. Programs with using functions are compact and easy to understand.
  4.Testing and correcting errors is easy because errors are localized and corrected.
  5.We can understand the flow of program and its code easily since the readability in enhanced while using the functions.
  6. A single function written in a program can also be used in other programs also.

#include <stdio.h>
/* function body */
int add (int x, int y){
 int z;
z = x + y;
return (z);
main ( )
int i,j,k;
i = 10;
j = 20;
k = add(i,j);  /* function call */
printf ("The value of k is %d\n",k);
The value of k is 30


Post a Comment

Codecademy Code Foundations

Popular Posts


Android (23) AngularJS (1) Assembly Language (2) Books (10) C (75) C# (12) C++ (81) Course (1) Data Strucures (4) Downloads (1) Engineering (13) flutter (1) FPL (17) Hadoop (1) HTML&CSS (40) IS (25) Java (89) Leet Code (4) Pandas (2) PHP (20) Projects (19) Python (434) R (69) Selenium Webdriver (2) Software (14) SQL (27)