Programmingoneonone is known for sharing best programming knowledge.

Categories of functions in c++ programming

In this post, you will learn about the categories of functions in c++ programming and learn about function arguments and function return type.

categories of functions in c++ programming, learn c++ programming
learn c++ programming


There are four categories of functions in c++ programming.

  • Function with no parameters and no return value.
  • Function with parameter and no return value.
  • Function with no parameter and return value.
  • Function with parameter and return value.

Function with no arguments and no return value.

the function which should not return any value and not pass any parameter list is called the function with no arguments and no return value.

Example:
              void fun(void);

Function with arguments and no return values.

the function which should not return any value and pass at least one parameter is called a function with arguments and no return value.

Example:
             void add(int,int);

Function with no arguments and return values.

the function which should return any type of value and do not pass any type of arguments is called a function with no arguments and return value.

Note: here I used int as a return type. but you can change the return type as per your need.

Function with arguments and return values.

the function which should return any type of value and pass at least one type of argument is called a function with arguments and return value.

Example:
             int add(int, int);

Example program to define the function type and call the functions:

    #include <iostream>

    void first(void); // function with no paramete and no return value
    void second(int); // function with parameter and no return value
    int third(void);  // function with no parameter and return value
    int fourth(int, int); // function with parameter and return value

    int main()
    {
      
      int a=10, b=20, c=30,d,e;

      first(); // calling first function

      second(a);

      d=third();

      std::cout<<"\n value of a in third functions is:"<< d;

      e=fourth(b,c);

      std::cout<<"\n value of a in fourth function is:"<< e;

      return 0;

    }

    void first()
    {

        std::cout<<"\n this is the function which has not any parameter and not any return type:";
    }

    void second(int x)
    {

        std::cout<<"\n this is the function which has a parameter and not any retur type:";
        std::cout<<" value of a in second function is:"<< x;
    }

    int third()
    {
       int y=5;
       std::cout<<"\n this is the function which has not any parameter but return a value:";

       return y;
    }

    int fourth(int x, int y)
    {
           int z;

           z=x+y;

           std::cout<<"\n this is the function which has returned the value and has a parameter                   list:";          

           return z;

    }

so, now I think you know what is parameter list and what is return type and type of functions in c++ programming.

"please share this post as much as possible as you can, and also comment me your questions and queries related to this topic"

No comments:

Post a Comment