C program has two types of functions:
1. Library Functions
2. User defined functions
Library
Functions:
These are the functions which are already written,
compiled and placed in C Library and they are not required to be written by a
programmer. The function’s name, its return type, their argument number and
types have been already defined. We can use these functions as required. For
example: printf(), scanf(), sqrt(), getch(), etc.
User defined
Functions:
These are the functions which are defined by user at
the time of writing a program. The user has choice to choose its name, return
type, arguments and their types. The job of each user defined function is as
defined by the user. A complex C program can be divided into a number of user
defined functions.
For example:
#inlcude<stdio.h>
double
convert (int) ; /* function proto type */
main()
{ int c ;
/* double
d ; */
printf (“Enter temperature in Celsius: ”) ;
scanf (“%d”, &c) ;
/* d = convert(c) ; */ /*Function call*/
printf (“The Fahrenheit temperature of %d C = $lf
F”;c, convert (c) ;
/* d inplace of convert */
}
double convert (int C) /* function definition */
{
double f ;
f = 9.0*c/5.0+32.0 ;
return f ;
}
What is about main( ) function?
The function main() is an user defined function except
that the name of function is defined or fixed by the language. The return type,
argument and body of the function are defined by the programmer as required.
This function is executed first, when the program starts execution.
Comments
Post a Comment