Function Types in C++
Types Of Function in C++
Four types of Function based on argument and return type
- Function - no argument and no return value
- Function - no argument but return value
- Function - argument but no return value
- Function - argument and return value
Function Types Diagram Representation
Syntax
// Function Declaration - no argument and no return value
void funtion1();
// Function Declaration - no argument but return value
int funtion2();
// Function Declaration - argument but no return value
void funtion3(int a,int b);
// Function Declaration - argument but return value
int funtion4(int a,int b);
Example Program
//Simple Function Types Example Program in C++
//Function Example
#include<iostream>
using namespace std;
void funtion1(); // Function Declaration - no argument and no return value
int funtion2(); // Function Declaration - no argument but return value
void funtion3(int a, int b); // Function Declaration - argument but no return value
int funtion4(int a, int b); // Function Declaration - argument but return value
int main() {
int x, y;
cout << "Simple Function Types Example Program in C++\n";
// Function Call - no argument and no return value
funtion1();
// Function Call - no argument but return value
x = funtion2();
cout << "\nReturn Value : " << x;
// Function Call - no argument and no return value
funtion3(10, 20);
// Function Call - no argument but return value
y = funtion4(100, 200);
cout << "\nAddition : " << y;
}
void funtion1() // Function Definition - no argument and no return value
{
cout << "\nIts simple function definition";
}
int funtion2() // Function Definition - no argument but return value
{
int c = 1000;
return c;
}
void funtion3(int a, int b) // Function Definition - argument but no return value
{
int c;
c = a + b;
cout << "\nAddition : " << c;
}
int funtion4(int a, int b) // Function Definition - argument but return value
{
int c;
c = a + b;
return c;
}
Sample Output
Simple Function Types Example Program in C++
Its simple function definition
Return Value : 1000
Addition : 30
Addition : 300
--------------------------------
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Exception Handling Divide by zero Using C++ Programming