C programming
Type of function:
- No return type no argument - void small ( )
- return type & no argument - int small ( )
- No return type & argument - void small ( )
- Return type & argument - int small ( int , int)
Advantages of function:
There are several advantages of function -
- Reduction in code redundancy
- Enabling code reuse
- Better readability
- Information hiding
- Improved debugging & testing
- Improved maintainability
Clarification of function:
Function can be classified as -
- user defined function
- Library function
1. Library function:
There are those functions whose functionality has already been developed by someone and are available to the user for use these are called library functions or pre defined function.
Ex. printf(), scanf(), sqrt(), pow() etc.
2. User defined function:
These are functions that are defined by the user at the time of writing a program the user. Develop the functionality by writing the body of the function also called programmer defined function.
Need of user defined function:
- Facilitates top down modules programming approach .
- Length of source program can be reduced
- Easy to locate and isolate a specific logic.
- A function can be used by many other programs.
Return type:
The return statement is used to return the result of the computation program control back to the calling function. There are three forms of return statement -
return i:
Used when function does not return any value.
return expression :
Used when function returns result of calling function to called function
function name:
The rule for a function name is same as for a variable name.
Type of parameter:
It specifies the kind of parameter that are used in function for eg. int, char, float etc.
Number of parameter:
It specifies how many parameter are used in function.
Ex.
Waf to add two numbers-
#incldue<stidio.h>
void sum (int,int)
main()
{
int a,b;
printf("Enter No.");
scanf("%d %d",&a,&b);
sum(a,b);
}
void sum (int c, int d)
{
int s;
s=c+d;
pritnf("Sum=%d",s);
}
Thank you,
keep supporting..............
Comments
Post a Comment