Briefly describe how parameter passing by-value and by-reference are accomplishe
ID: 3648185 • Letter: B
Question
Briefly describe how parameter passing by-value and by-reference are accomplished in memory. Write statement 1 to call method A below. Write statement 2 to call method B. Which method uses pass by-value? Which method uses pass by-reference?static void Main()
{
int balance = 15000;
//statement 1
//statement 2
}
//method A
public static void addBonus(ref int balance)
{
balance = balance + 1000;
}
//method B
public static int addBonus(int balance)
{
return (balance + 1000);
}
Explanation / Answer
Call By Value, the standard way of doing things in C and C++, is where a copy of an object is placed in the parameter stack. The called function can access and manipulate that copy at will, but it cannot change the original copy because it has no way of knowing where that original copy is located. Call By Reference, on the other hand, is where the address of an object is placed in the parameter stack. Using extra syntax, the * or the ->, the called function can access and manipulate the original copy at will. method A uses call by reference method B uses call by value.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.