Questions tagged [pass-by-value]

pass-by-value is a "one way passing" so that modifications of the passed value inside the receiving function (or other entity like process, etc) are not returned back.

pass-by-value is a one way passing so that modifications of the passed value inside the receiving function (or other entity like process, etc) are not returned back.

pass-by-value normally means cloning a variable and making a cloned copy available to the receiving function. Modifications of this copy are allowed, but they are not returned back to the caller; the copy is simply disposed after the call returns.

Passing by value is more secure if the function can also be called by malicious code (malicious code can retain the reference and observe it later even if it cannot modify it). Some are also convinced it results a cleaner code. However passing of the larger structures by value also requires more resources.

1173 questions
-2
votes
1 answer

pass by reference or by value in variable assignment of struct, Golang

type temp struct{ val int } variable1 := temp{val:5} // 1 variable2 := &temp{val:6} // 2 In 2, the reference is stored in the variable2. In 1, does the copy operation is taking place? Or variable1 is also pointed to the same memory portion? or…
Yousuf Ali
  • 23
  • 4
-2
votes
1 answer

C Pass By Reference Misconception

Specifics matter. Especially when talking about how something works, and even more so when we consider why something works. Currently, as I understand it, EVERYTHING in C is passed by value. NOTHING is passed by reference. Some programmers mention…
mindoverflow
  • 730
  • 4
  • 13
-2
votes
1 answer

c++ function call - pass by reference calls pointer method / pass by value calls referense method

A function call is made in the code. In the first function call a pass by reference is performed calling the pointer function. In the second function call a pass by value is performed where the reference function is called. Why is this so? #include…
forty4seven
  • 73
  • 1
  • 4
-2
votes
2 answers

Java ArrayList independent copy

I used the method below to make a copy of a list, as you can see the output, they are independent. Did I get something wrong? or are they really independent? because I did some research on the internet, and it told me this method should…
anon
-2
votes
1 answer

Why Python Dictionary behaves like object reference?

I need to work with dict from dict as a copy, but when I change this copy, the original dict changes too. The question is: "Is there any specific documentation, that describes this Python behavior?" b = {"first_first": 10} # internal dict a =…
-2
votes
2 answers

Any tips on getting around the pass-by-value issue?

In the code below I have a classic Java pass-by-value issue (written in processing; setup() == main). void setup() { A a = new A(); a.makeTheB(a.b); System.out.println(a.b); //Returns null } class A { B b; public void makeTheB(B…
-2
votes
1 answer

How to stop a variable from changing as and when the assigned variable value changes C#

I have two ObservableCollection variables temp and original of ObservableCollection datatype. I have assigned original = temp at some point. temp collection keeps changing with different values at different times. I want original to change only when…
-2
votes
1 answer

Is it most efficient to have all functions accept only parameter primitives wrapped by an object?

In JavaScript (or TypeScript), objects are passed by reference, unlike primitives which are copied in the function. Therefore, isn't it the case that this: sum(one: number, two: number): number { return one + two; } is always less efficient…
-2
votes
1 answer

Shoud Java be considered as "Strictly pass by value"?

In Pass By value when arguments are passed by value to a method, it means that a copy of the original variable is being sent to the method and not the original one, so any changes applied inside the method are actually affecting only the copy…
Mukul Bhardwaj
  • 562
  • 5
  • 16
-2
votes
2 answers

Pass pointer by reference

In attempting this HackerRank tutorial (in which you need to set a to a+b and b to |a-b|) I first attempted to modify the pointers to point to the new values: void update(int *a,int *b) { // Complete this function int sum = *a + *b; int…
LastStar007
  • 725
  • 1
  • 8
  • 21
-2
votes
4 answers

c - Sorting twenty ints using passByValue

So I got a homework assignment where I have twenty hardcoded ints, each a random number. Some can be the same. Using passByValue, I need print the three highest numbers. Now I already have this planned out. The numbers will be declared in main, each…
DFT95
  • 27
  • 5
-2
votes
1 answer

golang address of interface and interface difference

I have found many similar problem, but not what I want please see following codes. (1) var buf bytes.Buffer fmt.Fprint(&buf,"test") (2) var w…
nuclear
  • 3,181
  • 3
  • 19
  • 38
-2
votes
1 answer

receiving other reference type in Java

There is a parameter which is reference type, and can it receive other reference type? for instance, there is a code below fr = new FileReader("d:\\test.txt"); br = new BufferedReader(fr); the BufferedReader class receives FileReader type but I…
meBe
  • 154
  • 9
-2
votes
1 answer

Could not get the entered string from the stack of function

#include #include static void get_string(char *ac) { ac = (char *)malloc (1 * sizeof (char)); printf("Enter the string to count vowels and consonants in a string using pointers: "); scanf("%s", ac); } main(int…
jiju
  • 11
  • 2
  • 8
-2
votes
4 answers

Redefinition Error C++

I am having trouble with the portion where I need to print the day. I tried making a second variable but it is not working. Basically I take a user input for their birthday. Then I'm trying to call this function that determines the day of birth (it…
NICE8xx
  • 21
  • 1
  • 3