Function in C

The function in C language is also known as procedure in other programming languages.A function can be called many times. It provides modularity and code reusability.

Advantages of function in C

  • Code Reusability
  • Code optimization

Syntax:

return_typefunction_name(data_type parameter...){ 
//code to be executed
}        

				

Example of function in C


 #include<stdio.h>
#include<conio.h>
//defining function 
int cube(int n){ 
return n*n*n; 
} 
void main(){ 
int result1=0,result2=0; 
clrscr(); 

result1=cube(2);//calling function
result2=cube(3); 
printf("%d \n",result1); 
printf("%d \n",result2); 

getch(); 
} 

				

Output:

8
27