Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Explain "passing by value", "passing by pointer" and
"passing by reference" ?

Answer Posted / ranjeet garodia

Pass by value - a copy is made

Pass by pointer ( explicit pointer)
example:
void func(int * ptr_sent)
main()
{
int i;
int *p;
p = &i;
func(p);
}

void func(int * ptr_sent)
{
*ptr_sent = *ptr_sent + 2
// adds 2 to the value in location pointed by ptr_sent
}

answers given by yen .. there is one error ... in pass by
reference .. when calling function pass the variable not
the address....fun(i) should be called instead of fun(&i)

Pass by reference (implicit pointer)
example:
void func(int &ref_sent)
main()
{
int i;
func(i); // call by reference
}

void func(int &ref_sent)
{
ref_sent = ref_sent + 2
// adds 2 to the ref_sent
// Please note that you do not need * when using reference
// Any code manipulating reference reflects changes on i
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is purpose of new operator?

1069


How will you call C functions from C ++ and vice-versa?

1139


Write a program to find the reverse Fibonacci series starting from N.

1261


What is while loops?

1046


What is the this pointer?

1107


What are mutator methods in c++?

1157


What are the four partitions in which c++ compiler divides the ram?

1225


Explain the advantages of using friend classes.

1154


What is the best c++ book for beginners?

1142


How is c++ different from java?

1030


What is constructor in C++?

1080


Is c++ primer good for beginners?

1035


Explain virtual class?

1024


Write a program using merge () function to combine the elements of array x[ ] and y[ ] into array z[ ].

1053


What is do..while loops structure?

1139