A function is a subprogram that acts on data and often returns a value You are already familiar with  the one function that every C++ program possesses i.e int main( void).
Lets take an example of user defined function which is further used in main() function:


int main()
{
statement 1;
statement 2;
function1();
{
function_statement1;
function_statement2;
.
.
.
function_statementn;
}


function2()
{
function_statement1;
function_statement2;
.
.
.
function_statementn;
}
return 0;
}

Keep in mind when you are working with user defined function that your main() function should be very short and should consist only function call. The definition of all the function should be defined out the main() function of your program.
Each function has its own name, return type, number of argument and the sequence of these argument passed to the function. When the name of the function is encountered in the main(), the execution of the function body is executed from where this particular function is defined. When the function is finished its execution then its control is return to main() who called it and the program continue on to the next line of code after that.



Thanks
Mukesh Rajput


Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: