Function in C

Functions in C programming are used to divide a large program into sub-programs for easy control. All these sub-programs are called sub-functions of the program.

Function Program

Program

#include<stdio.h>
#include<conio.h>
void main()
{
void fun(); //defining Function 'fun()' for use, 'void' is must here.
fun(); //calling 'fun()' function.
printf("After Calling Function");
getch();
}
void fun() //this is 'fun()' function, 'void' is must here.
{
printf("This is Function\n");
}
Output
This is Function
After Calling Function

Function Program Another Method

Program

#include<stdio.h>
#include<conio.h>
void fun(); //defining Function 'fun()' for use, 'void' is must here.
void fun() //this is 'fun()' function, 'void' is must here.
{
printf("This is Function\n");
}
void main()
{
fun(); //calling 'fun()' function.
printf("After Calling Function");
getch();
}
Output
This is Function
After Calling Function

Program Calling Functions

Program

#include<stdio.h>
#include<conio.h>
void main()
{
void fun(); //defining Function 'fun()'.
void fun2(); //defining Function 'fun2()'.
void fun3(); //defining Function 'fun3()'.
fun2(); //calling 'fun2()' function.
fun3(); //calling 'fun3()' function.
fun(); //calling 'fun()' function.
printf("After Calling Functions");
getch();
}
void fun3() //this is 'fun3()' function.
{
printf("This is fun3() Function\n");
}
void fun() //this is 'fun()' function.
{
printf("This is fun() Function\n");
}
void fun2() //this is 'fun2()' function.
{
printf("This is fun2() Function\n");
}
Output
This is fun2() Function
This is fun3() Function
This is fun() Function
After Calling Functions