News:

Build a stunning handcrafted website with IT Acumens

Main Menu

Advantages of Functions

Started by thiruvasagamani, Sep 22, 2008, 10:28 AM

Previous topic - Next topic

thiruvasagamani

Reusability

eg:
max.c // suppose filename is max.c

int max( int x, int y)
{
-------
-------
-------
}
main()
{
-------
-------
-------
}
void f1()
{
-------
-------
-------
}

sample.c // another file

#include " max.c" // above max.c file is included in sample.c
main()
{
-------
-------
-------
ans = max( 10 , 20);
-------
-------
}

From the above functions defined in one program can be called from some another program .This is possible by # include " filename" max() is defined in max.c file , it is called from sample.c program .We don't want define max() again in sample.c instead include max.c. All functions of max.c are substituted in sample.c. Thus reuse the function but don't rewrite main() in max.c , main() must be commented, since program can contain only one main() function
Thiruvasakamani Karnan