How we can make simple returning user defined function in c++ code


It is very easy to understand the use of simple returning user defined function. By these functions we can make easy the code to understand. There are two types of the function more.
(i)Default Function                        (ii)Parametric Function

Simple Structure:


dataTypeName  FunctionName ()
{

}

Code without Prtotype:


#include <iostream>
using namespace std;
int ans;
int Fun(int a, int b)
{
                ans=a+b;
                return ans;
}
int main()
                {
                                int Total;
                                Total=Fun(2,8);
                                cout<<Total;
                }

Output:


10
Hope you understand the use of simple returning user defined in c++.

Code with Prototype:


#include <iostream>
using namespace std;
int ans;
int Fun(int a, int b);
int main()
{
                int Total;
                Total=Fun(2,7);
                cout<<"Total : "<<Total;
}
int Fun(int a, int b)
{
                ans=a+b;
                return ans;
}

Output:



avatar
AUTHOR: Muhammad Abbas
I am Software Engineer.

1 Comments
avatar

nice tutorial sir its solved my problem quickly

Replay