Address of the value is passed in the function, so actual and formal arguments share the same address space. Hence, value changed inside the function, is reflected inside as well as outside the function.
In this original value is modified because we pass reference (address).
e.g:#include<iostream.h> #include<conio.h> void swap(int &,int &); void main() { int a,b; clrscr(); cout<<"Enter values for a "; cin>>a; cout<<"Enter values for b "; cin>>b; swap(a,b); cout<<"After swap a = "<<a<<" and b = "<<b; getch(); } void swap(int &p,int &q) { int temp; temp=p; p=q; q=temp; cout<<"After swap a = "<<p<<" and b = "<<q; }O/P
Enter value for a 2 Enter value for b 4 After swap a = 4 and b = 2