Variations in Functions in C Language with Free Notes

Introduction – Functions

A complex problem may be decomposed into small or easily manageable parts or modulus called Functions. Functions are very useful to read, write, debug, and modify complex problems.

The user defined functions may be written in the following ways based on the arguments passed and the image of return Statement.

  1. Functions with no argument and no return value.
  2. Function with arguments but no return value.
  3. Functions with no arguments but a return value.
  4. Functions with arguments and return value.

1. Functions with no arguments and No Return value

In this type of Functions, main program will not send any arguments to the function and also the function will not return any value to the main program.

Example:

Here are the example of the Functions with no arguments and no return value,

/* Functions with no arguments and no return value*/
#include <stdio.h>
#include <conio.h>
    void main()
            { 
               clrscr();
               printf("\n You are Welcome to the main Progra");
               message();
               printf("\n Welcome back to the main");
            }
               message();
          }
               printf("\n Welcome to the Sub Program,");
        }
Free Hand-Written Notes

2. Functions with Arguments but no Return Value

In this category of the function, the main program or calling program will send some arguments value but called program or the function sub-program will not return any value.

It is the onw way communication between a calling portion of the program and the function block.

Example:

Here is the example of the Functions with arguments but no Return value,

/*Program with Arguments but no return value*/
#include <stdio.h>
#include <conio.h>
    void main()
            {
                void sum (int, int);     // Declaration
                 int a, b;
                 clrscr();
               printf("Enter the value of a & b");
                scanf("%d%d", &a, &b);
                sum(a, b);
                getch();
              void sum (a, b)
                int a, b:
                   {
                      int sum;
                      sum = a+b;
                      printf("sum = %d", sum);
                   }
Play Quiz Gain Knowledge

3. Functions with No Argument but Return a Value

In this category of the function or sub program, main program will not send any argument to the function but function sub-program will send (return) some value to the main program.

The data can be transferred only from the function block to calling function.

The Values a, b are entered on the function, calculation are performed in the function and after that result is calculated. It is returned to the calling function.

Example:

Here is the example of Functions with no arguments but return value,

/*Program with Arguments but no return value*/
#include <stdio.h>
#include <conio.h>
    void main()
            {
              int sum();   //Function Declaration 
              int result;
              result = sum();
                  printf(" sum is = %d", result);
                  getch():
             }
              int sum()     //Function Definition
                 {
                   int a, b, c;
                    Printf("\n Enter the value of a and b");
                    scanf("%d%d", &a, &b);
                    c = a+b;
                    return (c);
                 }

4. Functions with Arguments and a Return Value

In the Category of the Functions, the main program or the calling program will send arguments to the called program and at the end of the called program the function will send value back to the main program.

Data Communications takes place between both the calling portion of a program and the function block.

Example:

Let’s take an example of the Functions with Arguments and a Return value,

/*Program with Arguments and a return value*/
#include <stdio.h>
#include <conio.h>
    void main()
            {
              int sum(int, int);   // Declaration 
              int a, b, result;
                clrscr();
                Printf("\n Enter the value of a and b");
                scanf("%d%d", &a, &b);
                result = sum(a, b);
                  printf(" sum is = %d", result);
                  getch():
             }
              int sum( int a, int b)     // Definition
                 {
                   int c;
                    c = a+b;
                    return (c);
                 }

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top