CALL BY VALUE:
void swap(int a,int b)
{
int t;
t=a;
a=b;b=t;
}
void main()
{
int a=10,b=20;
printf("Before swapping : %d,%d\n",a,b);
swap(a,b);
printf("After
swapping : %d,%d\n",a,b);
}
OUTPUT
Before swapping : 10,20
After swapping :10,20
Explanation :the a,b in main() and swap() functions are
different....
So the changes made to a and b in the swap() function has no
affect on a and b of main().
No comments:
Post a Comment