Questions tagged [reference]

A reference is a value that enables a program to indirectly access a particular datum, such as a variable or a record, in the computer's memory or in some other storage device.

A reference is a value that enables a program to indirectly access a particular datum, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the datum.

In some programming languages, copying a variable may be implemented as either a copy by value or a copy by reference. When it is copied by reference, a reference to the data will be assigned, and the underlying data is not copied. Often, object datatypes will be copied by reference by default (for example, in Java), while primitives will be copied by value.

A nice article on pass by reference

17086 questions
3862
votes
44 answers

What are the differences between a pointer variable and a reference variable?

What is the difference between a pointer variable and a reference variable?
prakash
  • 58,901
  • 25
  • 93
  • 115
3259
votes
40 answers

How do I pass a variable by reference?

I wrote this class for testing: class PassByReference: def __init__(self): self.variable = 'Original' self.change(self.variable) print(self.variable) def change(self, var): var = 'Changed' When I tried…
David Sykes
  • 48,469
  • 17
  • 71
  • 80
1410
votes
23 answers

How to copy a dictionary and only edit the copy

I set dict2 = dict1. When I edit dict2, the original dict1 also changes. Why? >>> dict1 = {"key1": "value1", "key2": "value2"} >>> dict2 = dict1 >>> dict2["key2"] = "WHY?!" >>> dict1 {'key2': 'WHY?!', 'key1': 'value1'}
MadSc13ntist
  • 19,820
  • 8
  • 25
  • 19
1010
votes
28 answers

What's the difference between the 'ref' and 'out' keywords?

I'm creating a function where I need to pass an object so that it can be modified by the function. What is the difference between: public void myFunction(ref MyClass someClass) and public void myFunction(out MyClass someClass) Which should I use…
TK.
  • 46,577
  • 46
  • 119
  • 147
907
votes
12 answers

What's the difference between SoftReference and WeakReference in Java?

What's the difference between java.lang.ref.WeakReference and java.lang.ref.SoftReference ?
driekken
  • 11,443
  • 4
  • 19
  • 10
894
votes
61 answers

The located assembly's manifest definition does not match the assembly reference

I am trying to run some unit tests in a C# Windows Forms application (Visual Studio 2005), and I get the following error: System.IO.FileLoadException: Could not load file or assembly 'Utility, Version=1.2.0.200, Culture=neutral,…
leora
  • 188,729
  • 360
  • 878
  • 1,366
630
votes
10 answers

MongoDB relationships: embed or reference?

I want to design a question structure with some comments. Which relationship should I use for comments: embed or reference? A question with some comments, like stackoverflow, would have a structure like this: Question title = 'aaa' content =…
Freewind
  • 193,756
  • 157
  • 432
  • 708
628
votes
13 answers

Is there a difference between "==" and "is"?

My Google-fu has failed me. In Python, are the following two tests for equality equivalent? n = 5 # Test one. if n == 5: print 'Yay!' # Test two. if n is 5: print 'Yay!' Does this hold true for objects where you would be comparing…
Bernard
  • 45,296
  • 18
  • 54
  • 69
525
votes
16 answers

The type or namespace name could not be found

I have a C# solution with several projects in Visual Studio 2010. One is a test project (I'll call it "PrjTest"), the other is a Windows Forms Application project (I'll call it "PrjForm"). There is also a third project referenced by PrjForm, which…
Anders
  • 15,227
  • 5
  • 32
  • 42
470
votes
13 answers

Does JavaScript pass by reference?

Does JavaScript pass by references or pass by values? Here is an example from JavaScript: The Good Parts. I am very confused about the my parameter for the rectangle function. It is actually undefined, and redefined inside the function. There are no…
J Any
  • 4,847
  • 3
  • 13
  • 8
457
votes
17 answers

When to use references vs. pointers

I understand the syntax and general semantics of pointers versus references, but how should I decide when it is more-or-less appropriate to use references or pointers in an API? Naturally some situations need one or the other (operator++ needs a…
connec
  • 7,231
  • 3
  • 23
  • 26
445
votes
11 answers

Why can't I make a vector of references?

When I do this: std::vector hello; Everything works great. However, when I make it a vector of references instead: std::vector hello; I get horrible errors like error C2528: 'pointer' : pointer to reference is illegal I want to put…
Colen
  • 13,428
  • 21
  • 78
  • 107
422
votes
4 answers

JavaScript by reference vs. by value

I'm looking for some good comprehensive reading material on when JavaScript passes something by value and when by reference and when modifying a passed item affects the value outside a function and when not. I'm also interested in when assigning to…
jfriend00
  • 683,504
  • 96
  • 985
  • 979
406
votes
4 answers

Why can't I store a value and a reference to that value in the same struct?

I have a value and I want to store that value and a reference to something inside that value in my own type: struct Thing { count: u32, } struct Combined<'a>(Thing, &'a u32); fn make_combined<'a>() -> Combined<'a> { let thing = Thing {…
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
403
votes
1 answer

Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?

As far as I know, reference/pointer aliasing can hinder the compiler's ability to generate optimized code, since they must ensure the generated binary behaves correctly in the case where the two references/pointers indeed alias. For instance, in the…
Zhiyao
  • 4,152
  • 2
  • 12
  • 21
1
2 3
99 100