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 a storage class?

1368


What is endl c++?

1151


How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?

2367


What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor

1204


What is the use of structure in c++?

1079


What is the main use of c++?

1166


How compile and run c++ program in turbo c++?

1234


What is the use of lambda in c++?

1078


Is it possible to pass an object of the same class in place of object reference to the copy constructor?

1097


What is the difference between global variables and static varables?

1185


How a modifier is similar to mutator?

1236


how to access grid view row?

2283


How can a called function determine the number of arguments that have been passed to it?

1190


What are the advantages of prototyping?

1125


What is the difference between object-oriented programming and procedural programming?

1299