Saturday, 4 December 2010

rules for the functions


1. A function may contain many functions

Ex:
 void prime()
 {
   add();
   sub();
   div();
}

2. A function is called when the function name is followed by a semi colon.

Ex:
   void main()
   {
      max(a,b); //func. call
   }

3. A function is defined when the function names is followed by a pair of braces in which one or more statements may be present

Ex:
 int max(int a, int b)
 {
   if(a>b)
    return(a);
  else
    return(b);
}
4. A function can be called from any other function (even main() also) but can not be defined in another function
Ex:

int max()
{
  main();
  armstrong(n);
}

5. function can be called number of times

   void main()
   {
      max(a,b); //func. call
      max(a,b); //func. call
      max(a,b); //func. call
   }

6. a function can call it self( recursion)




No comments:

Post a Comment