Function and its working in c++ (part-2)

Hello guys!!! Welcome to New Age informers. I just revised my posts and note that two methods of function are remaining to teach you.So I decided to make part-2. Before starting this methods, you need to know about previous methods so this below link is the part-1.

https://newageinformers.blogspot.in/2017/06/functions-and-its-working-in-c.html


3) Take something returning nothing.
 here is the program,

#include<iostream.h>
void sum(int x,int y)        /*   definition  */
{
int z;
z=a+b;
cout<<\n"Addition is : " <<z;
}
void main()
{
int x,y;
cout<<"\n Enter values: ";
cin>>x;
cin>>y;
sum(x,y);                   /* call */
}

In above program, we took void type for not returning value and took two integer parameters (x and y). In main function we added two values into them. In definition part, we added another three variables (a,b,z). a and b will accept the value from x and y. z variable will store the answer of the program.
  So program starts from main function, it will enter two values. Next is call the sum function so it will go into the sum function and terminated.

4) Take nothing return nothing.
here is the program,

#include<iostream.h>
void sum()
{
int x,y,z;
cout<<"\n Enter values: ";
cin>>x;
cin>>y;
z=x+y;
cout<<"\n Addition of two numbers are "<<z;
}
void main()
{
sum();     /* call  */
}

In above program,we took void type for not returning value and took function name sum and we gave two integer numbers and stores in the third variable(z).
After completing process we call the function from the main function. Program will work same as above program
So this is it guys!!! Will be coming soon with interesting posts.
Until then bye bye!!!
For different updates follow us here:

Facebook: CLICK HERE!!!!!!!!!!
 
Twitter: @NewAgeInformers

Instagram: @new_age_informers   

Youtube: CLICK HERE!!!!




Comments