Function in C language :

What is function ?

Functions are subprograms which are used to compute a value or perform a task. They cannot be run independently and are always called by the main() program or by other functions.
There are two king of functions :

  • Library or built-in functions (scanf(), printf(), strcpy, strcmp, strlen, strcat etc.)
  • User-defined functions

  • User-defined functions :

    In C language, functions are declared to compute and return the value of specific data type to the calling program.
    Functions can also be written to perform a task. It may return many values indirectly to the calling program and these are referred as void function (Defined by the user at the time of writing the program) .

    Uses of functions :

    function are very much useful when a block of statements has to be written/executed again and again.
    Functions are useful when the program size is too large or complex.
    Functions are also used to reduce the difficulties during debugging a program.

    Function Declaration :

    Syntax :

    1. type name ( type argu1, type argu2, ..., type argu n )
    2. {
    3. <local declaration>
    4. - - - -
    5. <statement block>
    6. - - - -
    7. return(variable or expression);
    8. }

    where type is the type of the value return by the function and argument expected.
    argu1, type argu2, ...,argu n are the arguments which are variables that will received the values from the calling program.
    name is the name of the function by which the function is called by the calling program.

    Example :

    1. /* Description: function to find factorial of an integer */
    2. int fact(int k)
    3. {
    4. int i,p = 1;
    5. for(i=1;i<=k;i++)
    6. p = p * i;
    7. return(p);
    8. }

    Next Update

    Loading...

    Currently we improved our website User Interface and other contents. Our next update is adding video tutorials on this site so, We create a new YouTube channel, our YouTube channel name is CodeX.

    We need some time for make video tutorials (CodeX) so, stay with us and keep supporting and you know already we make a Collaboration with HackIsOn YouTube channel long time ago So, please Subscribe Our Channels