I am providing you with an example in C++. I am sure that you will get some ideas about calling the "main" function :
Code:
// function example
#include <iostream>
using namespace std;
int addition (int a, int b)
{
int x;
x=a+b;
return (x);
}
int main ()
{
int y;
y = addition (2,6);
cout << "The result is " << y;
return 0;
}
The parameters and arguments have a clear correspondence. Within the main function we called to addition passing two values: 2 and 6, that correspond to the int a and int b parameters declared for function addition. At the point at which the function is called from within main, the control is lost by main and passed to function addition. The value of both arguments passed in the call (2 and 6) are copied to the local variables int a and int b within the function. Function addition declares another local variable (int x), and by means of the expression x=a+b, it assigns to x the result of a plus b. Because the actual parameters passed for a and b are 2 and 6 respectively, the result is 8.
Bookmarks