most of time passing by reference and by address seems same, or most of us consider them same but their is difference in both technique.
When we pass a variable to a function by reference,it mean we are passing alias of variable. and in address we are passing their actual address through pointer variable.
Example will clear the concept
void add(int&)
void main()
{
int i=10;
add(i);
cout<<"\ni="
}
void add(int& a)
{
a+=20;
}
<*********-------->>>>>><<<<<<<<---------------------******************
by address
void add(int*)//prototype
void main()
{
int i=10;
add(&i);
cout<<"\ni="<}
void add(int* a)
{
*a=*a+20;
}
output i=30
Wednesday, December 10, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment