Questions tagged [pass-by-reference-value]
15 questions
5
votes
2 answers
Lua : copying a table efficiently (deep copy)
I try to make efficiently a copy of a lua table. I have written the following function copyTable() that works well (see below). But I imagined I could have something more efficient using the "passing by value" mechanism of the functions. I made a…

user1771398
- 475
- 6
- 18
2
votes
1 answer
Java passByValue or Reference confusion
I was trying to play with Java references and I got an interesting situation.
This following piece of code gives unpredictable output to me. I am trying to modify an array, a string and an integer in a function.
public static void main(String[]…

thatman
- 333
- 3
- 14
2
votes
1 answer
Stopping reference variables changing the value of the original variable
I am assigning the value of a custom class to another variable. Updating the value of the new variable is affecting the value of the original variable. However, I need to stop the reference variable from updating the original variable.
Here's a…

Micah Simmons
- 2,078
- 2
- 20
- 38
1
vote
0 answers
Passing Arguments by Value and by Reference in VBA
In VBA, if I want to pass arguments ByVal and ByRef simultaneously. As far as I understand it the following code should work just fine (and so far my test confirms that):
Sub Test(ByVal Var1 As String, ByRef Var2 as String, Var3 as String, ByVal…

Albin
- 1,000
- 1
- 11
- 33
0
votes
0 answers
Are classes'objects, in python 3.9, passed by reference?
I have read, multiple times, that python passes arguments by value. However, I was testing the following simple code, and it looks like the class c objects are passed by reference (a modification inside the function modifies the object). Could…

user18170958
- 1
- 1
0
votes
1 answer
setting hardware configuration bits in hardware using JS
My problem can be reduced to this trivial (or so it seemed) bit of code
var myArray = [1,2];
function addOnetoArrayElement(element){
element +=1;
console.log(element); // Returns 3
}
addOnetoArrayElement(myArray[1]);
console.log(myArray[1]); …
0
votes
0 answers
Python Pass by assignment but value is not retained
I am having this issue in a large code base so I created a small reproducer below:
Here, I have the following two functions, func2() and func3()
def func2(a,b):
a = 'new-value'
b = b+1
return a, b
def func4():
x,y =…

Balaji V. Iyer
- 1
- 2
0
votes
2 answers
Difference between const reference and reference
void setage(const int&a);
void setage(int&a);
What is the difference between this two functions?
When this function is called?

Nagappa
- 194
- 2
- 13
0
votes
0 answers
How to have a higher level function check variables within lower functions via pass by reference?
We haven't really covered pointers but have been learning about passing by reference (the & pointer will be covered later). In an exercise, we were asked to write a small question game that would pass values in a simple one class main program…

mobcity zkore
- 263
- 1
- 8
0
votes
1 answer
Use variable value as Environment parameter in GoCD
I'm trying to write a shell script which read variables from a file and replace that with the Environment variable define in GoCD.
Now the challenge i'm facing is i'm trying to use value of variable as parameter
Below is my script
#!/bin/bash…

Yushi
- 416
- 6
- 24
-1
votes
5 answers
Java Pass by value
Possible Duplicate:
Java, pass-by-value, reference variables
Consider the following simple java program
class main{
public static void main(String args[]){
int x = 5;
change(x);
…

nikhil
- 9,023
- 22
- 55
- 81
-1
votes
2 answers
Java Pass by Reference/Value
I have read and (believe I have) understood the posts made previously on this forum.
However as a Java novice I am having an issue
I create a MAP voucherDetails and pass it into a function where it is being populated (verified with trace). On…

Ephraim
- 199
- 1
- 2
- 18
-1
votes
1 answer
How to re-code PHP assign-by-reference usage
My deprecation checker is throwing this error:
Using deprecated language feature assign by reference(&=) Since PHP 5.3 use normal assignment instead.
So, I am trying to figure out how to re-code the methods in this class to not use by reference or…

craigh
- 1,909
- 1
- 11
- 24
-1
votes
3 answers
Java pass by value query
Since java is pass by value.In below code we are passing a value to appendStringMethod not a reference, then why in main method we get HelloWorld not just Hello after calling appendStringMethod() in main.
public class test {
public static void…

Sanjay Singh
- 307
- 1
- 3
- 13
-2
votes
2 answers
What does "There may be many references to the same object." mean?
Section 4.3.1 of the Java Language Specification states that, "There may be many references to the same object.".
But it also states that "The reference values (often just references) are pointers to these objects, and a special null reference,…

constantem
- 71
- 2
- 6