Page 8 - Sample_test_Float
P. 8

8  Functions and Pointers



               Syntax
               ReturnType FunctionName(ArgumenTtype with VariableName)
               {

                   Block of statements;
               }
               Block of statements may include variable declarations, statements and return value.


              Note: The return statement forces the function to return immediately eventhough if function is not yet completed.


               Example of function definition
               int add(int a,int b)
               {
                  int c;
                  c = a+b;
                  return c;
               }

              Note: In the argument list of function definition, you specify the variable name also.A semicolon should not be placed at
              the end of the first line of the function definition.


               Another Example
               int add(int a,int b)
               {
                  int c;
                  return c;
                  c=a+b;
               }

              Here the function terminates after reaching the return statement without executing the statement “return c.”


               Example Program

               #include<stdio.h>
               int add(int a,int b) //Function Definition
               {
                  return a+b;
               }
               void main()
               {
                  int x=10,y=20;
                  int sum;
                  sum = add(x,y);// Function Calling
                  printf(“\nSum =%d”,sum);
               }

               Output
               30
   3   4   5   6   7   8   9   10   11   12   13