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

Are strings immutable in c++?

1217


What is runtime polymorphism in c++?

1226


Does c++ have arraylist?

1077


What is c++ library?

1090


what is a class? Explain with an example.

1187


What methods can be overridden in java?

1338


Give example of a pure virtual function in c++?

1238


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

1111


What is function overloading c++?

1123


What is ios :: in in c++?

1106


Define upcasting.

1090


Which bit wise operator is suitable for checking whether a particular bit is on or off?

1082


In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that

1158


Explain terminate() function?

1102


What are the two shift operators and what are their functions?

1141