Simple Example Program for Function In C++

Definition

A function is like a black box. It takes in input, does something with it, then spits out an answer.

We have some terminology to refer to functions:

  • A function, call it f, that uses another function g, is said to call g. For example, f calls g to print the squares of ten numbers.
  • A function's inputs are known as its arguments
  • A function g that gives some kind of answer back to f is said to return that answer. For example, g returns the sum of its arguments.

Syntax

return_type function_name(argumnent)
{
 // body Of the Function
}

Simple Example Program for Function

/*  Example Program For Simple Example Program Of Function In C++
    little drops @ thiyagaraaj.com

    Coded By: THIYAGARAAJ MP             */

#include<iostream>
#include<conio.h>

using namespace std;

// Simple Function printmessage()
void printmessage() {
    cout << "Im Function In C++";
}

int main() {
    //Call Simple Function printmessage()
    printmessage();
    getch();
    return 0;
}

Sample Output

Im Function In C++