Skip to main content

Function Types in C++

3 min read Updated June 30, 2026
Share:
On this page (8sections)

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

Function Types In C++

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
--------------------------------

How It Works

This C++ program demonstrates Function Types. It first prepares the data it needs, then performs the core operation step by step, and finally prints the output shown in the Sample Output above.

  1. Declare the variables that hold the program’s data.
  2. Print the final result to the console so you can compare it with the sample output.

Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.

Continue learning with these related tutorials and programs:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Function Types, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses core C++ syntax, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials