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
-1
votes
1 answer

Java Pass-by-Reference Confusion/Example

This may be a case of semantics but as a practical matter I've been finding that Java absolutely acts sometimes in a pass-by-reference manner as opposed to pass-by-value. For example: public String example() { SimpleDateFormat f = new…
Palladium
  • 65
  • 7
-1
votes
2 answers

PInvoke Class by value for c++ struct

I've got a small issue regarding P/Invoke. Currently, I am implementing a wrapper for a C API for a hardware device whose original C# implementation sucks. The issue/inconvenience I am having is the following: The API implements multiple structs for…
-1
votes
1 answer

If Java is pass by value, how can some methods modify some parameters passed to it?

I don't have an exact example, but i know that some Java methods can modify the parameters passed to it, and where the method was called can use these modified values.
Steven
  • 319
  • 1
  • 3
  • 7
-1
votes
4 answers

Understanding Java Arrays

Please look at the following code : public static void main(String[] args) { Random random = new Random(); int[] array = new int[10]; Arrays.setAll(array, operand -> random.nextInt(10)); System.out.println(Arrays.toString(array)); …
FaNaJ
  • 1,329
  • 1
  • 16
  • 39
-1
votes
2 answers

Creating a tail and head in a list by value in C

I want to create a list in C that the head and tail are NOT pointers, but a nodes by value. can it be done? I want to use the head and the tail as an empty frame to put the list between. I do know how to create it as pointers and only want to know…
Ron Aham
  • 27
  • 4
-1
votes
1 answer

program that shows how to pay out change

I have written the following code to determine how to pay out change: #include #define twentyDollar 2000 #define tenDollar 1000 #define fiveDollar 500 #define oneDollar 100 #define quarters 25 #define dimes 10 #define nickels 5 #define…
MatthewS
  • 455
  • 2
  • 7
  • 22
-1
votes
2 answers

Can i pass value by reference in java

Code snippet public void parsequery() { ParseQuery query = ParseQuery.getQuery("Products"); query.whereEqualTo("StoreID", StoreID); query.findInBackground(new FindCallback() { public…
-1
votes
3 answers

Does Java pass-by-value for arrays?

I have a question regarding the concept of Java using pass-by-value. I do a lot of programming in C but I am very inexperienced with Java so I have been writing some code to learn a bit more about it. I have read many stack-overflow questions…
zephyrJ
  • 58
  • 6
-1
votes
2 answers

Java - Parameter Passing Confusion

"Java is pass-by-value" -Java Language Specification However, there are things that confuses me. Please take a glimpse of my example public class Main { public static void main(String[] args) { StringBuilder myBuilder = new…
-1
votes
2 answers

What is pass-reference-by-value?

I came across this yesterday and was wondering what the relationship of pass-by-value, pass-by-reference and pass-reference-by-value is. How do they all behave? Which programming language uses which? Additionally: I have also occasionally heard…
Sarien
  • 6,647
  • 6
  • 35
  • 55
-1
votes
6 answers

C++ : how does class variable get modified?

From the MSDN page concerning const functions The code: // constant_member_function.cpp class Date { public: Date( int mn, int dy, int yr ); int getMonth() const; // A read-only function void setMonth( int mn ); // A write…
user137263
  • 747
  • 5
  • 11
  • 25
-1
votes
2 answers

Python: how to check if an argument's type is such that it will be passed by value or by reference?

It seems that atomic types (int, string, ...) are passed by value, and all others (objects, pointers to functions, pointers to methods, ...) are passed by reference. What is the best way to check if a variable will be passed by value or by…
Yulia V
  • 3,507
  • 10
  • 31
  • 64
-1
votes
2 answers

C++ speed differences of "by value" vs "by reference"

I want to test speed of the passing by value and passing by reference in C++: class MyAddress{ char *name; long int number; char *street; char *town; char state[2]; long zip; std::vector v_int; public: …
4pie0
  • 29,204
  • 9
  • 82
  • 118
-2
votes
0 answers

What is the different between pass by value and pass by reference in python with reference to function arguments

I read many articles saying python is pass by value and some say python is pass by reference. Can anyone explain what is really is with some example?
Ashutosh Das
  • 31
  • 1
  • 7
-2
votes
2 answers

Program sadly crashes and I have no clue why

Does anyone know why this program crashes at "printf", I have no idea to be honest, thanks in advance. enter image description here Added from comments: #include #include #include typedef struct{ char…