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
#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