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<iostream.h>
#include<conio.h>
void main()
{
void fun(); //defining Function 'fun()' for use, 'void' is must here.
fun(); //calling 'fun()' function.
cout<<"After Calling Function";
getch();
}
void fun() //this is 'fun()' function, 'void' is must here.
{
cout<<"This is Function"<<endl;
}
Output
This is Function
After Calling Function

Function Program Another Method

Program

#include<iostream.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.
{
cout<<"This is Function"<<endl;
}
void main()
{
fun(); //calling 'fun()' function.
cout<<"After Calling Function";
getch();
}
Output
This is Function
After Calling Function

Program Calling Functions

Program

#include<iostream.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.
cout<<"After Calling Functions";;
getch();
}
void fun3() //this is 'fun3()' function.
{
cout<<"This is fun3() Function"<<endl;
}
void fun() //this is 'fun()' function.
{
cout<<"This is fun() Function"<<endl;
}
void fun2() //this is 'fun2()' function.
{
cout<<"This is fun2() Function"<<endl;
}
Output
This is fun2() Function
This is fun3() Function
This is fun() Function
After Calling Functions