#include<iostream.h>
void main(void)
{
void display(void);
display();
}
void display(void)
{
cout<<"This is a test program\n";
cout<<"for demonstrating function call";
cout<<"in c++\n";
}
Output:
This is a test program.
For demonstrating function call.in c++
Type 2:
This user defined function passes some formal arguments to a function but does not return value to the caller. This is one way data communication.
Example
#include<iostream.h>
void main(void)
{
void sum(int, int);
int x,y;
sum(x,y);
}
void sum(int a, int b)
{
cout<<a+b;
}
Type 3:
This type of user defined function passes some formal argument to a function from the calling portion of the program and the computed value is returned back to the caller. Data communication both a way.
Example:
#include<iostream.h>
void main(void)
{
fload sum(float, float, float);
float x,y,z;
cot<<"enter the value\n";
cin>>x>>y>>z;
float total;
total=sum(x,y,z);
cout<<"total value of x,y,z is";
cout<<total;
}
float sum(float a, float b, float c)
{
float temp;
temp=a+b+c;
return(temp);
}
Output:
enter the value
1 2 3
total value of x,y,z is 6
void main(void)
{
void display(void);
display();
}
void display(void)
{
cout<<"This is a test program\n";
cout<<"for demonstrating function call";
cout<<"in c++\n";
}
Output:
This is a test program.
For demonstrating function call.in c++
Type 2:
This user defined function passes some formal arguments to a function but does not return value to the caller. This is one way data communication.
Example
#include<iostream.h>
void main(void)
{
void sum(int, int);
int x,y;
sum(x,y);
}
void sum(int a, int b)
{
cout<<a+b;
}
Type 3:
This type of user defined function passes some formal argument to a function from the calling portion of the program and the computed value is returned back to the caller. Data communication both a way.
Example:
#include<iostream.h>
void main(void)
{
fload sum(float, float, float);
float x,y,z;
cot<<"enter the value\n";
cin>>x>>y>>z;
float total;
total=sum(x,y,z);
cout<<"total value of x,y,z is";
cout<<total;
}
float sum(float a, float b, float c)
{
float temp;
temp=a+b+c;
return(temp);
}
Output:
enter the value
1 2 3
total value of x,y,z is 6
No comments:
Post a Comment