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 / ven

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
}

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

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 ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is rtti in c++?

1057


Explain polymorphism?

1030


Out of fgets() and gets() which function is safe to use?

1067


How do you invoke a base member function from a derived class in which you have not overridden that function?

1070


Define basic type of variable used for a different condition in C++?

1046


Is c++ an oop?

1021


Does improper inheritance have a potential to wreck a project?

1083


What are structs in c++?

967


what is data encapsulation in C++?

1009


Explain dangling pointer.

1073


How to tokenize a string in c++?

1000


How is computer programming useful in real life?

999


What is microsoft c++ redistributable?

1024


Which c++ operator cannot overload?

918


Define pointers?

1002