These aer different ways of passing arguments to functions..
1%26gt; Pass by value..
In this only the value is copied into the dummy paramenters and if the value is changed inside the function then its not reflected back into the actual parameters ..
Syntax of defining: int swap(int a, int b);
2%26gt; pass By reference
in this an alias name is created for the actual parameters, if the value is changed inside the function then its reflected back into the actual parameters Its like working on the actual parameters itself
Syntax of defining: int swap(int %26amp;a, int %26amp;b);
3%26gt; pass by address
In this, the address of the actual parameters is passed, so there must be a pointer to catch it.
Syntax of defining: int swap(int *a, int *b);
The call for all the above will be the same
main(){
int x=4,y=3;
swap(x,y);
}
imperial
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment