Questions tagged [pass-by-reference]

Pass by reference is an argument marshalling strategy whereby a variable's location in memory is passed to a function, rather than a copy of the variable's value, although the function appears in the source code to receive the variable itself rather than a pointer to it.

Passing by reference means that the memory address of a variable is passed rather than a copy of the variable's value.

This typically means that the function can modify the passed variable, assigning a new value to it. However for performance reasons, passing by reference may be useful even if the passed structure is not modified, as with the Pascal var modifier, and some programming languages have constructs (like the C const modifier) to disallow modification of a variable passed by reference.

4485 questions
1
vote
4 answers

reference objects in generics c#

How i can use ref of a generic class as parameter and change data. Here is my sample code bool IRequestHandler.ParseRequest(string request, ref T obj) { var req = RequestHandlerGateway.DeserializeFromXml(request,…
RPK
  • 33
  • 1
  • 5
1
vote
8 answers

Retrieve property by reference

I am new in C#. I am from Java world. So I am confused with the following code: class A { private PointF point; public A(PointF point) { this.point = point; } public PointF Position …
Michael Z
  • 3,883
  • 10
  • 43
  • 57
1
vote
7 answers

pointer and reference both in arguments

I saw in couple of tree codes that a function of tree class has both * and & with node for example to insert a node in a BST a function is like this insertnode(node * &t,string value) { t = new node; t-> val = value // code to find right place…
sparkling_spark
  • 85
  • 2
  • 10
1
vote
4 answers

Is this pass by reference or by value?

Lets say I have the following: class MyClass { // ... } void doSomething (MyClass instance) { // Is instance passed by reference or by value (copied)? } void main () { MyClass instance = MyClass(); doSomething(instance); } In…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
1
vote
2 answers

PHP: Store and/or pass reference to class

Given the following structure: class B { private $_b; private __constructor() { } public function setValue( $value ) { $this->_b->setValue( $value ); } public static function load( &$__b ) { $B = new…
Nahydrin
  • 13,197
  • 12
  • 59
  • 101
1
vote
5 answers

C++ - passing parameter by reference in a function which returns int

I have created a C++ program in order to test the functionality of passing parameters by reference for functions. #include using namespace std; int f(int &b) { b = b + 1; cout << b << endl; return b; } int main() { int…
Simon
  • 4,999
  • 21
  • 69
  • 97
1
vote
3 answers

why java RMI can't get return value by reference

In RMI, I can only get return value by InetSocketAddress address = new InetSocketAddress(hostname, port); Server server = Stub.create(Server.class, address); int return = server.getValue(); But, I can't get it by public class Return { int…
Helin Wang
  • 4,002
  • 1
  • 30
  • 34
1
vote
6 answers

How can I avoid ref parameters?

I have a method that has 2 ref parameters: public void ReplaceSomething(ref int code, ref string name) { ... } I want to avoid this, as it is not a good design (and scales poorly). What are my options? I've though about using an anonymous…
Otuyh
  • 2,384
  • 5
  • 22
  • 40
1
vote
3 answers

Passing global variable by reference and modifying the referenced variable

What's the right way to do... var array1 = [] var array2 = [] function doIt(arg){ var myArray; if(arg == 1){ myArray = array1 }else if(arg == 2){ myArray = array2 } myArray.push('test'); } doIt(1); //array1…
userBG
  • 6,860
  • 10
  • 31
  • 39
1
vote
3 answers

Pass by reference in java?

I'm trying to build a litle gam for android GSMs. I hava lots of units and all of them have destinations. To calculate destination I'm using a function called CalDes. This function CalDes is calculating my unit's speed. So I'm sending some variables…
Evren Ozturk
  • 918
  • 2
  • 19
  • 39
1
vote
6 answers

Java Memory, Pass-by-Value, Pass-by-Reference

Possible Duplicate: Is Java pass by reference? I have a question about passing by value and passing by reference in java. I have a "Graph" class that I wrote to display a long array of doubles as a graph, The (simplified) constructor looks like…
Chris192
  • 43
  • 5
1
vote
3 answers

Java Variable References when using Lists

Just a thought question here. In C++, I could do the following: vector > data; // add data into data //.. data[0].push_back( "somedata" ); And I would expect somedata to get written to the vector array because the [] notation gives…
Authman Apatira
  • 3,994
  • 1
  • 26
  • 33
1
vote
1 answer

JNI how get values updated to int and double fields

How do two values I pass into my JNI tossed down to C then C does its changes and updates the values. How do I get those two values(maxPower, index) and see then in Java? They always come back as zero. JNIEXPORT jdouble JNICALL Java_com_TV ( …
JPM
  • 9,077
  • 13
  • 78
  • 137
1
vote
3 answers

Assigning default values to arguments passed by reference

I want to do something like this: int displayAll(Message *m, string &lastIndex, int &NumPrinted = 0 ); It gives me error, cribbing about int to int&. I tried this too: int temp =0; int displayAll(Message *m, string &lastIndex, int &NumPrinted =…
AJ.
  • 2,561
  • 9
  • 46
  • 81
1
vote
3 answers

How to pass char array as reference to a function and memcpy in

I've been struggling to fix this since morning. The value 'pd' pm doesn't change outside the function. Could someone tell me what the mistake is? void foo(u8 *pm, u8 *pd) { pm = "IWR "; memcpy(pd, pm, sizeof(pm)); printf("in foo pm =…
swap
  • 69
  • 1
  • 3
  • 8