Sunday, 8 March 2015

Functions in C


The C functions that you have used so far (such as printf and scanf) are built into the C libraries, but you can also write your own functions. Therefore functions can be classified as built-in and user defined. A modular program is usually made up of different functions, each one accomplishing a specific task such as calculating the square root or the factorial. In general a modular program consists of the main( ) function followed by set of user defined functions as given below:

#include ……
#define …..

Prototypes of functions

int main( )
{
……….
}
function_1( )
{
………..
}
function_2( )
{
………..
}
…………
function_n( )
{
………..
}
The source code contains other elements in addition to the function blocks. It starts with the #include directive, followed by the #define directive (if any) then followed by the proto types of functions. The prototype is a declaration of a function used in the program. Then comes the program building block which includes the main( ) function and implementation of the user defined functions.

No comments:

Post a Comment