All Questions
Tagged with pass-by-reference parameter-passing
236 questions
2
votes
4
answers
96
views
Iterating over an Array
I tried this block of code and it yields two different results
public class PassArrayToFunction {
public static void increase1(int[] arr){
for(int a: arr)
a += 1;
}
...
-3
votes
1
answer
115
views
Is it better to pass a C++ object by reference than by value if it is in RAM? [closed]
There is a widespread opinion that in the C++ language it is better to pass an object to a function by reference than by value (thus supposedly reducing the number of copies). But what if this object ...
0
votes
3
answers
218
views
itk c++ function parameter passing
I am trying the simple act of writing a function (encapsulation) that calculates an histogram from the input via the itk ImageToHistogramFilter. While this works fine I do not seem to be able to get ...
1
vote
1
answer
161
views
Pass list of arguments to ggstatsplot function
I am using ggstatsplot to make lots of similar plots but the exact data or variable plotted will be different between each plot. I want to assign most of the (constant) arguments to a variable that I ...
0
votes
2
answers
88
views
How to pass DOMDocument to Subroutine
I have a bunch of so called "structured data" from the German commercial register which comes in xml-files (one file always holds the data of one company). The data structure corresponds to ...
1
vote
3
answers
137
views
C program calling malloc results in bus error?
I have written this code to declare a pointer, p, and then dynamically allocate 4 bytes of memory for type int to then store some data in it. p should point to an address which holds the data 6 of ...
0
votes
0
answers
42
views
Language C - function for Realloc struct pointer [duplicate]
I'm trying to build a function that realloc a struct pointer (which works as an arrays of structs), but it is not working out:
I guess I'm not using the pointer reference correctly int the function ...
1
vote
1
answer
65
views
Pass pointer to pointer behaves weird
I am solving Leetcode problem #94 for in-order traversal of a binary tree.
I cannot understand why - when I use &cpy (currently commented) when calling helper() the program works correctly but not ...
0
votes
1
answer
335
views
How to get the name of the current environment THIS within a function
It looks like you can have one function pass data back transparently to a parent function with the assign operation.
Example (Setup)
calling = function()
{
a = 25;
cat("\n ...CALLING....
0
votes
2
answers
64
views
Implications of pass-by-value vs pass-by-reference in C# [duplicate]
I was following along a tutorial online about C#. The tutorial talks about passing-by-reference vs passing-by-value. What I am confused about specifically is that since in C#, there is a distinction ...
-2
votes
1
answer
200
views
Why should I copy the array element by element and then append to list instead of appending directly?
In the below code I am printing all the subsets using backtracking.
I am printing the res_list at last.
res_list = [[], [13], [12], [12, 13]]
when I copy element by element of subset_list into a list ...
0
votes
0
answers
122
views
Which operator must be disabled to prevent passing by value
Of all the moove, copy, copy assign... operators
Which must be deleted to avoid an object from being passed by value? For example.
class MyClass { int val; };
As is the following can be declared:
...
0
votes
2
answers
670
views
Passing variables of different types by reference as arguments to same variadic parameter
I've been struggling with golang's lack of optional parameters, so I have been using the closest workaround: variadics. Even though I got it working, it is messy attempting to pass multiple variable ...
0
votes
1
answer
74
views
PHP how come one element of the array is by reference and the other by value when passing a two element array as a by value parameter?
Can someone explain this strange behaviour I am witnessing in PHP 8.1.6?
I guess the behaviour is according to standards, I just don't understand it. The function call has a parameter by value, yet ...
0
votes
0
answers
337
views
How to pass template variadic arguments by reference in C++?
I want to get repeated inputs, therefore I made the function to get inputs with variety of types.
template <typename InputType>
void get_inputs(const std::string& placeholder, InputType& ...