These are the in- -built functions of ‘C ’library. These are already defined in header files. e.g. printf( ); is a function which is used to print at output. It is defined in ‘stdio.h ’ file . Programmer can create their own function in C to perform specific task
Advantages of function
(1) Function with no arguments and no return values. (2) Function with arguments and no return values. (3) Function with arguments and return values. (4) Function with no arguments and return values.
 When a function has no arguments it does not receive any information from the calling function.  Similarly when it does not return any value the calling function does not receive any information from the called function.
 Function has the actual arguments that are assigned to the formal arguments in the function definition. o Actual parameters are used in the function call. o Formal parameters are used in function definition. o Both the arguments should match in number, type and order. o The values of actual arguments are assigned to the formal arguments on a one to one basis starting with the first argument.
 The function call transfers the actual arguments to the particular function where the formal arguments are created and are assigned the memory space and are given the values of the actual arguments.  The called function is executed until the return statement is encountered. The return value is passed back to the function.  The return value is thus assigned to the calling function.
 When a function has no arguments it does not receive any information from the calling function.  The called function is executed until the return statement is encountered. The return value is passed back to the function.
When we use value during the function call then it is known as call by value.
#include <stdio.h> Void main() { Void swap(int,int); Int x=10,y=20; Swap(x,y); Printf(“x=%d & y=%d”,x,y);
Void swap(int a,int b) { Int t; t=a a=b b=t; Printf(“x=%d & y=%d”,a,b,); }
 In this instead of passing value, address are passed.  Here formal arguments are pointers to the actual arguments  Hence change made in the argument are permanent.
Void main() { int a=10
void swap(int *x,int *y) { int z; z=*x; *x=*y; *y=z; Printf(”x=%d&y=%d”,*a*b);
Output: before function calling a= 10 b= 25 value of x=25 and y=10 after function calling a=25 b= 10
 In recursion, function may directly or indirectly call it self – If the call to a function occurs inside the function itself it is called direct recursion.  If the function calls another function, which in turn makes a call to the first one, it is called indirect recursion.
<type> function name(<argument list>) { ……………… ………………. function name(…); ……………… ….............. }
 Avoids unnecessary calling of functions.  Solves problems in easier way than using iterative loop. You reduce size of the code when you see recursive call.  Complex programs can be easily written using recursion.
 Too many recursive functions may cause confusion in the code.  Recursive solution is logical and it is difficult to debug and understand.  Program execution becomes slower as the function call and return takes longer time.
Functions (Computer programming and utilization)

Functions (Computer programming and utilization)

  • 4.
    These are thein- -built functions of ‘C ’library. These are already defined in header files. e.g. printf( ); is a function which is used to print at output. It is defined in ‘stdio.h ’ file . Programmer can create their own function in C to perform specific task
  • 5.
  • 7.
    (1) Function withno arguments and no return values. (2) Function with arguments and no return values. (3) Function with arguments and return values. (4) Function with no arguments and return values.
  • 8.
     When afunction has no arguments it does not receive any information from the calling function.  Similarly when it does not return any value the calling function does not receive any information from the called function.
  • 9.
     Function hasthe actual arguments that are assigned to the formal arguments in the function definition. o Actual parameters are used in the function call. o Formal parameters are used in function definition. o Both the arguments should match in number, type and order. o The values of actual arguments are assigned to the formal arguments on a one to one basis starting with the first argument.
  • 10.
     The functioncall transfers the actual arguments to the particular function where the formal arguments are created and are assigned the memory space and are given the values of the actual arguments.  The called function is executed until the return statement is encountered. The return value is passed back to the function.  The return value is thus assigned to the calling function.
  • 11.
     When afunction has no arguments it does not receive any information from the calling function.  The called function is executed until the return statement is encountered. The return value is passed back to the function.
  • 12.
    When we usevalue during the function call then it is known as call by value.
  • 13.
    #include <stdio.h> Void main() { Voidswap(int,int); Int x=10,y=20; Swap(x,y); Printf(“x=%d & y=%d”,x,y);
  • 14.
    Void swap(int a,intb) { Int t; t=a a=b b=t; Printf(“x=%d & y=%d”,a,b,); }
  • 15.
     In thisinstead of passing value, address are passed.  Here formal arguments are pointers to the actual arguments  Hence change made in the argument are permanent.
  • 16.
  • 17.
    void swap(int *x,int*y) { int z; z=*x; *x=*y; *y=z; Printf(”x=%d&y=%d”,*a*b);
  • 18.
    Output: before function callinga= 10 b= 25 value of x=25 and y=10 after function calling a=25 b= 10
  • 20.
     In recursion,function may directly or indirectly call it self – If the call to a function occurs inside the function itself it is called direct recursion.  If the function calls another function, which in turn makes a call to the first one, it is called indirect recursion.
  • 21.
    <type> function name(<argumentlist>) { ……………… ………………. function name(…); ……………… ….............. }
  • 22.
     Avoids unnecessarycalling of functions.  Solves problems in easier way than using iterative loop. You reduce size of the code when you see recursive call.  Complex programs can be easily written using recursion.
  • 23.
     Too manyrecursive functions may cause confusion in the code.  Recursive solution is logical and it is difficult to debug and understand.  Program execution becomes slower as the function call and return takes longer time.