Question

When you write code, how do you know that you need to use value or reference?...

When you write code, how do you know that you need to use value or reference? Please show with an example. I know reference is two way communication but it is not clear to me. Thanks

Homework Answers

Answer #1

We should use value when we don't want the changes done to formal functional arguments to be reflected back to the actual arguments.

For example, when we want to want to find the maximum of two numbers using a function which accept two integers, we write a function for the same. In this case, we should used pass by value since we don't want the changes to the formal arguments to be reflected back to the actual argument.

Now, let us consider another function which accepts an array and then sorts the same array. In this case, we should use reference since the actual array argument should be sorted after the control returns to the callee function.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
you need to write the code for the obstacle infra red sensor. They don't use an...
you need to write the code for the obstacle infra red sensor. They don't use an actual distance, that's an adjustment made on the hardware, you need to write the code for if they detect anything. HCSR04 ultrasonic sensor with arduino Please help me with this
i need to write an outline for research paper about gwedolyn brooks. i dont know how...
i need to write an outline for research paper about gwedolyn brooks. i dont know how to do it. please help me.
How do you calculate an equilibrium constant for n-propyl alcohol and acetic acid? I really need...
How do you calculate an equilibrium constant for n-propyl alcohol and acetic acid? I really need the step by step so that I can understand this. Thanks in advance and if you need further information for this please let me know I and I can get it.
Hi, I'm currently stuck with my homework. I need to know how to write this program...
Hi, I'm currently stuck with my homework. I need to know how to write this program in Python as below: Write function repeatPhrase(phrase, n), which prints the given phrase n times, alternating between lowercase and uppercase. For example, repeat('The sky is blue', 5) would print: the sky is blue THE SKY IS BLUE the sky is blue THE SKY IS BLUE the sky is blue Please help me, thank you very much!
When naming chemical elements, how do I know when to use the prefixes (mono-,di-,tri-, etc.) or...
When naming chemical elements, how do I know when to use the prefixes (mono-,di-,tri-, etc.) or the roman numerals in paranthesis? I noticed I am getting some wrong. Sometimes I don't need the prefixes at all or sometimes I need the parenthesis instead of the prefixes or vice versa. I know there are different compounds when it comes to naming such as binary compounds, polyatomics, transition metals, etc. I need some clarification on the topic. For example, GaBr3 is Gallium(III)...
Hello Everyone, I need to write a Python code for AES encryption and decryption for any...
Hello Everyone, I need to write a Python code for AES encryption and decryption for any text entered by the user. Can anyone please help me out with it? Thank you so much.
MATLAB question and do not change subject. if you dont know skip I need a working...
MATLAB question and do not change subject. if you dont know skip I need a working MATLAB code which will tell me the type of damping which is present in the system. there are 3 types of damping . use if else and give the result. take mass stiffness damping coefficient as input. Dont post wrong answer of i will badly dislike
PLEASE SHOW WORK AND CALCULATE WITH FORMULAS OR EXPLANATION!! THANK YOU SO MUCH. ( please write...
PLEASE SHOW WORK AND CALCULATE WITH FORMULAS OR EXPLANATION!! THANK YOU SO MUCH. ( please write the formula first so i know the appropriate formula to use thanks!) What is the value in the year 2040 of an $800 a year annuity with the first payment in 2023 and final payment in 2039. The interest rate is 7% p.a. Please show me the line too.
how do you calculate the value of a firm's shares. please need guide thanks
how do you calculate the value of a firm's shares. please need guide thanks
How do you know whether to use the saturated steam tables or superheated steam tables? How...
How do you know whether to use the saturated steam tables or superheated steam tables? How do you know if it’s superheated or saturated, please give an example.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT