Topics

6/recent/ticker-posts

Functions In C Language



    
       Functions


 

Function is a set of statements to perform some task.

 

In C – language every task handled by the function. Hence C – Language is called as functional oriented language.

 

 

What is the difference between function and procedure  ?

 

Function and procedure both are set of statements to perform some task, the difference is that,

Function returns a value, where as procedure do not return a value.

 


Advantages of using functions.

 

1.Using functions we can avoid repeated code. Hence length of the code will be reduced ( code reusability )

 

2.Easy to develop the applications as each functions treated as separate units.

 

3.With functions we can get application modularity .

 

4.easy to maintain projects.

 

 

Disadvantages :

 

1.Time taken to jump the control between functions (considerable compared to development efforts )

 

2.If programmer is not expert in using recursive functions, there is a chance raising stack over flow exception.

 

 

                                                

Types of functions:

1.         1. Built-in functions

2.     2User defined functions

 

Built-in functions:

These are from C-Library files ( header files ).


Eg:

            printf(), scanf();

 

 

User defined functions:

These are developed by the programmers.

 

 


Defining a function:

 

function()

{

   ==========;

   ==========;

   ==========;

}

 

In a function every statement should be terminated with semicolon ( ; )

 

Calling a function:

 

main()à calling function

{

            ================;

================;

================;

function();

================;

================;

================;

}

 

function()à called function.

{

            ================;

================;

================;

================;

}

 

 

Important facts about functions.

 

1.C – Program is a collections of functions

 

2.To compile C – Program at least one function required.

 

3. C-Program compiles form top to bottom but execution starts from main()

 

4.To compile C-Program main() function is not compulsory but to create exe file and execute main() function should be required.

 

5. There is no limit on no of functions to be defined.

 

6.There is no order of defining functions, any function can be defined any where in the program, even before the   main() function also can be defined.

 

7. There is no priority of functions, all are equal, even main()  also equal to other functions.

 

8. Any function can be called from any function, even main() function can also be called from any other function.

 

9.execution of functions depends on sequence in the main().

 

10. main() is starting point of execution. It is controller of C-Application

 

11.A function calling itself is called as recursive function.

 

12.main() function, neither user defined nor pre-defined . It is an interface between user ( programmer ) and system.

 

Post a Comment

0 Comments