Functions in C++, Steps for writing Function explain with example.

Functions in C++ :
A complex parts may be decomposed into a small or easily manageable parts or modules called functions. Functions are very useful to read, write, debug and modify the complex program. Functions are used to implement reusability of code .
The main Function: In C++ the main() function returns a value of type int to the operating system.
int main()
{
…………
…………….
return 0;
}
Steps of writing Functions :-
1. Function Prototyping :- Here we write the Function prototype, which represents the name of function, number of input arguments and data-types of input arguments. The prototype describes the function interface to the comiler.
Syntax :- return-data-type function-name ( input-argument-list along with their data-types) ;
Example :- int add (int, int) ;
2. Function Definition :- Here we use along with the prototype, Opening and Closing curly brackets, inside which we write the code of the function.
Syntax :- return-data-type function-name ( input-argument-list along with their data-types) { …. }
Example :- int add (int a, int b) { return (a+b) ; }
3. Function Calling :- Here we use the function prototype, with out the return type and passing in the real arguments. It causes the function to execute its code.
Syntax :- function-name ( argument-values) ;
Example :- add (10 , 20 ) ;
return statement: The keyword return is used to terminate the function and return a value to its caller. The return statement may also be used to exit a function without returning a value. The return statement may or may not include an expression.
Syntax:- return;
return (expression);
Labels: C++