Functions:-
set of statements in which we will divide our programme so that it becomes easy to use.
Two types of Function:-
1.Library function:-
Pre-defined in compiler
example: printf(), scanf(), gets(), puts(), etc.
2. User-Defined Function:
Function -defined by user
Syntax:-
<Data type><function name>(<list of argument/parameter>)
{
body of function;
}
Data Type: It defines how much memory the function will occupy.
a)VOID:-
1. No memory space.
2. Never return a value.
3. can't make further expressions of the result given by the function.
b)Int/Float etc.
1. Memory space according to data type.
2. It must return a value.
3. can make further expressions.
Argument/Parameter:-
Term used to transfer the data from one function to another function.
a)Formal Argument:-
1. Argument at definition time of function.
2. can have a zero or 'n' number of formal arguments and declare them independently.
3. No, their own value.
b)Actual Argument:-
1. Argument at the calling or execution time of a function.
2. The number of actual arguments and there data type must be the same as in a formal argument.
3. use to assign their values to the formal argument.
Example:-
void add(int a,int b)
{
int c;
c=a+b;
printf("%d",c);
}
void main()
{
add(5,8);
add(10,15);
add(12,7);
}