In programming, we have 4 ways of defining a function and they are :-
A class in C++ can have all the 4 above mentioned types of member functions as per requirement.
Types of Function
Syntax :
// Function Declaration - takes nothing and returns nothing void funtion1();
// Function Declaration - takes nothing and returns something int funtion2();
// Function Declaration - takes something and returns nothing void funtion3(int a, int b);
// Function Declaration - takes something and returns something int funtion4(int a, int b);
Example :
// Simple Function Types Example Program in C++
// Function Example
#include <iostream>
using namespace std;
void funtion1(); // Function Declaration - takes nothing and returns nothing
int funtion2(); // Function Declaration - takes nothing and returns something
void funtion3(int a, int b);
int funtion4(int a, int b); // Function Declaration - takes something and return something
int main() {
int x, y;
cout
Output :
Simple Function Types Example Program in C++
It's simple function definition
Return Value: 1000
Addition: 30
Addition: 300