INTERVIEW QUESTIONS
C++
ARRAYS, STRINGS, POINTERS AND REFERENCES IN C++
DETAILS
Question: Explain "passing by value", "passing by pointer" and "passing by reference"
Answer: There is major defference between these three are when we want to avoid making the copy of variable and we want to change value of actual argument on calling function. there are we use passing by pointer,passing the reference. We can not perform arithmentic operation on reference.
|
Question:
Explain "passing by value", "passing by pointer" and "passing by reference"
Answer:
There is major defference between these three are when we want to avoid making the copy of variable and we want to change value of actual argument on calling function. there are we use passing by pointer,passing the reference. We can not perform arithmentic operation on reference. Source: CoolInterview.com
when we pass the object to afunction as an aguments its called pass by vaue.<br>when we pass the address of an object to function its called pass by refrence. Source: CoolInterview.com
Answered by: deepak kandpal | Date: 8/29/2009
| Contact deepak kandpal
By value<br>void fun(int,int);//declaration<br>fun(a,b);//call<br>By reference<br>void fun(int&,int&);<br>fun(a,b);<br>By address<br>void fun(int*,int*);<br>fun(&a,&b); Source: CoolInterview.com
Answered by: seema | Date: 9/22/2009
| Contact seema
1. When pass by value a copy of object is passed to the called function. Advantage is that the called function can not alter the value because it is working on a copy, not the actual variable.<br><br>2. Pass by Ref. When a ref is passed, it is the alias. So whatever the called function does with the ref, the change would be reflected in the original variable too. So this might be disadvantage too. The method of passing offers advantage of lesser stack memory used. Source: CoolInterview.com
Answered by: Achal Ubbott | Date: 11/30/2009
| Contact Achal Ubbott
1. When pass by value a copy of object is passed to the called function. Advantage is that the called function can not alter the value because it is working on a copy, not the actual variable.
2. Pass by Ref. When a ref is passed, it is the alias. So whatever the called function does with the ref, the change would be reflected in the original variable too. So this might be disadvantage too. The method of passing offers advantage of lesser stack memory used Source: CoolInterview.com
Answered by: GaneshRam | Date: 7/8/2010
| Contact GaneshRam
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|