GeekInterview.com
Series: Subject: Topic:
Question: 277 of 357

Difference between pass by reference and pass by value?

Asked by: Interview Candidate | Asked on: Jun 24th, 2005
Showing Answers 1 - 5 of 5 Answers
yogeshpanda

Answered On : Sep 19th, 2005

View all answers by yogeshpanda

If the base want to retain the ownership of the variables then it passed the variables to the function by referenc, and if it does`t want to retain the ownership of the variables then it passed the variables to the function by value. 

  
Login to rate this answer.
yogeshpanda

Answered On : Sep 19th, 2005

View all answers by yogeshpanda

If the base want to retain the ownership of the variables then it passed the variables to the function by referenc, and if it does`t want to retain the ownership of the variables then it passed the variables to the function by value. 

Yes  1 User has rated as useful.
  
Login to rate this answer.
Silvio

Answered On : Jul 4th, 2008

View all answers by Silvio

When using by reference there is no new variable just a alias to the memory address, if this parameters is not constant it is possible to change the content of that address.When using by value a new variable will be created in memory and it is impossible to change the original content.Everything depend on what you want to do.

Yes  1 User has rated as useful.
  
Login to rate this answer.

There two ways can passes an argument to subroutine (method).1)call-by-value2)call-by-referencecall-by-value:----------------In this process first method copies the value of an argument in to formal parameters of the subroutine. Therefore any changes made to the parameter of the subroutine will have no effect to argument used to call it.call-by-reference:---------------------In this process method copies the value of an argument in to the formal parameter of the subroutine. Therefore any changes made to the parameter of the subroutine will have effect to the arguments used to call it.

  
Login to rate this answer.

Pass By Ref is used Generally, when the Caller wants to retain the ownership of the variable.Most Imp, Pass By ref is used mostly, when Function Chaining / Assignment Chaining is to be implemented.With Basic Data type in C, when I say a = b = c = 4; it automatically assign 4 to a, b, c.But with any of my own object, say of class myClass, like:class myClass {...};myClass mObj1, mObj2, mObj3;...mObj1 = mObj2 = mObj3;...Proper assignment will happen only, when assignment operator is implemented with Pass By Ref & Return by Ref.i.e.myClass& myClass::operator=(myClass& myObj){...}

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.