- The functions are classified into the following types depending on whether the arguments (parameters) are present or not and whether the value is returned or not.
- These are also called function prototypes.
- The following are the function prototypes.
- The called program does not receive any data from the calling program and does not send back value to the calling program.
- This function is used to perform the only operation they act independently (They read data values and print results in the same block.
#include<iostream.h>
#include<conio.h>
int add();//fun declaration
int a,b;
void main()
{
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
add();//func
calling
getch();
}
int add() //fun definition
{
int c;
c=a+b;
cout<<"Sum is "<<c;
}
#include<iostream.h>
#include<conio.h>
int add();//fun declaration
int a,b;
void main()
{
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
add();//func
calling
getch();
}
int add() //fun definition
{
int c;
c=a+b;
cout<<"Sum is "<<c;
}
- The called program receives some data from the calling program and does not send back any values to the calling program. (One-way communication).
#include<iostream.h>
#include<conio.h>
int add(int,int);//fun declaration
void main()
{
int a,b,c;
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
add(a,b);//func
calling
getch();
}
int add(int x,int y) //fun definition
{
int z;
z=x+y;
cout<<"\nSum is "<<z;
}
#include<iostream.h>
#include<conio.h>
int add(int,int);//fun declaration
void main()
{
int a,b,c;
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
add(a,b);//func
calling
getch();
}
int add(int x,int y) //fun definition
{
int z;
z=x+y;
cout<<"\nSum is "<<z;
}
- The called program receives some data from the calling program and sends back any values to the calling program. (Two-way communication)
#include<iostream.h>
#include<conio.h>
int add(int,int);//fun declaration
void main()
{
int a,b,c;
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
c=add(a,b);//func
calling
cout<<"\nResult is ....."<<c;
getch();
}
int add(int x,int y) //fun definition
{
int z;
z=x+y;
return z;
}
#include<iostream.h>
#include<conio.h>
int add(int,int);//fun declaration
void main()
{
int a,b,c;
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
c=add(a,b);//func
calling
cout<<"\nResult is ....."<<c;
getch();
}
int add(int x,int y) //fun definition
{
int z;
z=x+y;
return z;
}
- The calling program cannot pass any arguments to the called program but, the called program may send some return value to the calling program.
#include<iostream.h>
#include<conio.h>
int add();//fun declaration
int a,b;
void main()
{
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
cout<<"\n Result is...."<<add();//func
calling
getch();
}
int add() //fun definition
{
int c;
c=a+b;
return c;
}
#include<iostream.h>
#include<conio.h>
int add();//fun declaration
int a,b;
void main()
{
clrscr();
cout<<"Enter
two values: ";
cin>>a>>b;
cout<<"\n Result is...."<<add();//func
calling
getch();
}
int add() //fun definition
{
int c;
c=a+b;
return c;
}
No comments:
Post a Comment