DECLARATION AND DEFINITION OF FUNCTIONS

Like variables functions also must be declared before the first call. Declaration of a function reveals the name of the function, number and type of parameters and type of their returning value. Declaration doesn’t contain description what and how function works, but gives the function prototype. The declaration of the function has the following form:
Returning type name of the function (type argument 1, type argument 2);
Returning type – determines which type of data will be return as a result of function execution,
Name_of_the_function – is a name of the function for example factorial,
Argument1 and argument2 that are inside the brackets are data which is given to a function during function calling. Number and type of arguments can be arbitrary, whereby function can be without arguments. Functions with unknown number of arguments can also be declared. Number of arguments and their order and type are called function signature.
As  a very easy example let’s use a function which calculates the square of a number. Let’s call this function square. Arguments of that function will be a number x which needs to be squared. So after the name of the function in brackets we need to define the type of an argument after which we write x. Function as a result will return the square of the number; so let’s assume that the returning type of the function is double. Declaration of function called sqare() will look like this:
double sqare(float x);
This is only a prototype of the function. For now we’ve defined the function – but we have not write the code of the function, we have not defined what and how the function works. The program for calculating sqare of the number is given below:
#include "stdafx.h"
#include "iostream"
using namespace std;
double sqare(float x); //Function declaration
double square(float x) {
       return x*x;
}
int _tmain(int argc, _TCHAR* argv[])
{
       float x;
       cout << "Enter the value of parameter x = " << endl;
       cin >> x;
       cout << "The result of x^2 is: "<< square(x) << endl;
       system("pause");
       return 0;
}
The instructions that are performed during the function call are called the function body. The function body always starts after the left curly bracket, and ends with the right curly bracket.  In previous example the function body consists of only one instruction and the function of that instruction is to multiply or to get a square of number x. The keyword return suggests that the multiplication x * x transfers as return value in part of the program that called the function.
Declaration and definition of the function can be separated and placed in different places of program code. Declaration must be defined in every program before function calling, before first calling. This is necessary so that compiler should be able to generate machine code for function calling (that code depends on function signature. Definition of the function can be placed in only one part of the program. Every call of that function will be, when connecting the program, focus on that definition.
So the function must be declared in original code before we make a first call. Definition of the function with shape must completely agree with the declaration.
If definition and declaration of the function are different, the compiler will report an error. So the function declaration and function definition must match, and also type of function, number, order and the type of arguments also must match.
Name of the arguments in the declaration and definition of function can be different. Moreover, in declaration of function the name of arguments can be neglected, which means that the upper declaration can be written in the following form as:
Double square (float).

After the function is declared (or eventually defined), we can call her from arbitrary  point in our program but for function calling we have to indicate the name of the function and in brackets we need to specify parameters. 
Share on Google Plus