programplug Logo




C++ Call By Reference


original value is modified

Passing arguments to a function copies the address of an argument into the formal parameter.In call by reference, original value is changed or modified because we pass address(reference).So actual and formal arguments shares the same address space.


#include
void incre(int  *v)
{
    *v = *v+1;
}
int main()
{
     int n=10;
     incre(&n);
     cout<<"Value of number is:" << n;
     return 0;
}

Output :
Value of number is: 11


Example : Swapping numbers using Function Call by reference


#include
void swap(int *a, int *b)
{
 int temp;
 temp=*a;
 *a=*b;
 *b=temp;
}
void main() 
{  
 int a=400, b=200;   
 swap(&a,&b);
 cout<<"Value of a:" << a;
 cout<<"Value of b:" << b;  
}  

Output:
Value of a: 200
Value of b: 400






Our Services

Developing Cheapest Websites
Offer Digital Marketing
Provide College Projects
Attractive Website Developing
Summer Training,Industrial Training
SCO,SMO

Contact Us

Dehradun Uttarakhand India
www.programplug.com
info@programplug.com
08534019974
Designed By : Mridul Gupta

Other Link

About Us

Contact Us

Disclaimer

Privacy Policy