+ 3
1.)-The main objective of the function is to make rigid and hard programs easier to understand.
2.)-Advantages of functions:-The functions are like modules which remain undisturbed until you call it.
You call functions whenever you want to do a specific work.
Instead of typing same text again and again programmer type it once in a function and use it whenever necessary by calling it.
3.)-There are 4 parts of function:-
a.)-Function Prototype
b.)-Function Definition
c.)-Function Body
d.)-Function Call
4.)-The syntax of Function Prototype is:
return_type function_name(function parameters each with their type)
5.)-The syntax of Function definition is same as Function Prototype. The only difference between Prototype and Definition is that after Definition you write body of the function.
6.)-Function Body:-It describes what work function is doing.
7.)-Function Call :-Calls the function whenever or wherever necessary.You can store return value of function in a variable.
8.)-Example of program using function:-
#include<iostream.h>
void main()
{
int sum(int a,int b);. //Function Prototype
int x=10,y=60;
cout<<"The sum of x and y is"<<sum(a,b); //Function Call
return;
}
int sum(int a,int b) //Function Definition
{
int sum=a+b; //Function Body
return sum;. //Returning variable sum
}
Note:-However the function definition and Prototype can be same but in this case before calling function you must have its prototype.
However,I tried hard to explain this but still I feel you must refer some other material.
+ 2
Functions are like separate blocks of code outside of main. If you make a function it needs a data type and a name. It may also have parameters passed to it. A good example of this is :
Int function(int x)
{
Return x * 2;
}
Int main()
{
Int x;
Cout << "enter a number: ";
Cin >> x;
Cout << "your number times 2 is: ";
<< function(x) << endl;
Return 0;
}
This program will prompt the user for a number and then the function will take that number and multiply it by two and return it to where the function has that value of a number times 2. Then when you call the function in your program, it will display your number times 2. Hope this helps.



