I'm trying to understand the conceptual difference between call by reference, value, and name.
So I have the following pseudocode:
<code>foo(a, b, c)
{
b =b++;
a = a++;
c = a + b*10
}
X=1;
Y=2;
Z=3;
foo(X, Y+2, Z);</code>
What's X, Y, and Z after the foo call if a, b, and c are all call by reference? if a, b, and c are call-by-value/result? if a, b, and c are call-by-name?
Another scenario:
<code>X=1;
Y=2;
Z=3;
foo(X, Y+2, X);</code>
I'm trying to get a head start on studying for an upcoming final and this seemed like a good review problem to go over. Pass-by-name is definitely the most foreign to me.
Reference - https://www.scaler.com/topics/c/call-by-value-and-call-by-reference-in-…
3 Replies
This article may be more relevant to your understanding, since this shows some demonstrable outputs based on the input conditions.
https://www.javatpoint.com/call-by-value-and-call-by-reference-in-c
Just to also ring ones noodles - with RUST programming language - this is left a little Vague.
( the older documentation has the FAQ - the newer site here: does not...)
https://prev.rust-lang.org/en-US/faq.html#why-no-stable-abi
Really most Rustaceans learn rust via this portal: https://doc.rust-lang.org/stable/rust-by-example/
I will break down this pseudocode based on different parameter passing mechanisms by taking this example:
foo(X, Y+2, Z);
If parameters are passed by reference:
After the function call, X will be updated to 11 (since a is 1 and a++ is 2, then c = 1 + 2*10 = 21 and X will be assigned 21), Y and Z remain unchanged.
If parameters are passed by value/result:
If parameters are passed by name:
Check out Cloud Computing and DevOps courses to learn and implement these codes.