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" ?

Answers were Sorted based on User's Feedback



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

Answer / roshanpr

During pass by value a duplicate copy of the parameters
passed are created. Any changes made to copy will not
reflect the actual parameters.

In pass by pointer(it called as pass by address) duplicate
copy is not created. and any chagnes made to copy will
reflect in actual parameters also.

Is This Answer Correct ?    10 Yes 1 No

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

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

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

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

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

Answer / sampurna pandey

i am not agree with Ranjeet, you mention this

main()
{
int i;
func(i); // call by reference
}

but fun(i) is a call by value not call by reference

your code will give compile error.

Ven eample is right.

Is This Answer Correct ?    1 Yes 1 No

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

Answer / sanish joseph

In Pass by value,copy of the value is passed, but in pass by
reference the address of the variables are passed as a
reference.pointer are variables storing the address of
another variable so it can be used as a pass by referece,
den it s teamed "passing by pointer".

Is This Answer Correct ?    3 Yes 4 No

Post New Answer

More C++ General Interview Questions

What is a sequence in c++?

0 Answers  


What are the different types of comments allowed in c++?

0 Answers  


Describe private, protected and public?

0 Answers  


Explain the use of this pointer?

0 Answers  


What is the difference between mutex and binary semaphore?

0 Answers  


What is tellg () in c++?

0 Answers  


What are friend classes? What are advantages of using friend classes?

0 Answers  


Write a program to get the value of sin (x) using a library function , when x is given in degrees.

1 Answers  


how to explain our contribution in the project?

0 Answers   Wipro, Yahoo,


Declare a class vehicle and make it an abstract data type.

0 Answers  


Write about a nested class and mention its use?

0 Answers  


There are 100 students in a class. The management keep information in two tables. Those two tables are given like Roll no Name Age 001 ABC 15 002 XYZ 14 and Roll No Subject Marks 001 Math 75 001 Physics 55 002 Math 68 001 Hindi 69 They want the information like this Roll No Name Hindi Physics Math Total 001 ABC 69 55 75 199 002 XYZ 68 74 84 226 And Roll No Suject Highest 001 Math 98 007 Physics 84 021 Hindi 74 All 275 All information is kept in structure in main memory. You have to find last two tables.

0 Answers  


Categories