In C++, a parameter can be passed by:
Each parameter's mode is determined by the way it is specified in the function's header (the mode is the same for all calls to the function). For example:
void f( int a, int &b, const int &c );
Parameter a is a value parameter, b is a reference parameter, and c is a const-reference parameter.
Value Parameters
When a parameter is passed by value, a copy of the parameter is made. Therefore, changes made to the formal parameter by the called function have no effect on the corresponding actual parameter.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
float r ,a;
float cir(float);
clrscr();
printf("Enter the Radius=\n");
scanf("%f",&r);
a=cir(r);
printf("\nThe area is %f",a);
getch();
}
float cir(float p)
{
return(3.142*p*p);
}
Output :
Enter The Radius
4
The Area =50.240002
- value,
- reference, or
- const-reference
Each parameter's mode is determined by the way it is specified in the function's header (the mode is the same for all calls to the function). For example:
void f( int a, int &b, const int &c );
Parameter a is a value parameter, b is a reference parameter, and c is a const-reference parameter.
Value Parameters
When a parameter is passed by value, a copy of the parameter is made. Therefore, changes made to the formal parameter by the called function have no effect on the corresponding actual parameter.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
float r ,a;
float cir(float);
clrscr();
printf("Enter the Radius=\n");
scanf("%f",&r);
a=cir(r);
printf("\nThe area is %f",a);
getch();
}
float cir(float p)
{
return(3.142*p*p);
}
Output :
Enter The Radius
4
The Area =50.240002
Pankaj Gaikar is a
professional blogger
from Pune, India who writes on Technology, Android,
Gadgets, social media and latest tech updates at
Punk Tech
,
Being Android
&
Shake The Tech
. Email me
HERE
0 comments :
Post a Comment