Values, References and Aliasing
A reference is a value that identifies an object rather than holding an independent copy of its data.
Summary
A reference is a value that identifies an object rather than holding an independent copy of its data. Aliasing occurs when multiple variables or access paths designate the same object. Assignment behavior depends on the language: copying a reference preserves access to the same object rather than duplicating it.
Mutation changes an existing object's state, so its effects can be observed through other aliases. Rebinding changes only a variable's association with a value or object.
| Operation | Result | Sharing |
|---|---|---|
| Reference copy | Copies a reference value | Same referenced object |
| Shallow copy | Creates a new outer object | Nested objects can remain shared |
| Deep copy | Recursively duplicates object structure | Governed by language or library rules |
Pass-by-value can copy a reference into a parameter. The function can then mutate the shared object, but rebinding that parameter does not rebind the caller's variable. Pass-by-reference instead aliases the caller's variable itself.
Identity means being the same object; equality means having equivalent content under the language's comparison rules. Immutable objects prevent mutation-related aliasing surprises even when references are shared. Decisions about sharing and copying affect memory use, execution cost, and ownership of mutable data. Tests of nested collections should check outer-object independence separately from nested-content independence.
Common Misconceptions: Copying a reference does not duplicate its object. A shallow copy does not guarantee independent nested contents. Passing a reference by value is not the same as pass-by-reference.
🧠 Key Concepts
- Reference Values
- Value Copying
- Aliasing
- Mutation
- Rebinding
- Shallow Copy
- Deep Copy
- Identity versus Equality
- Pass by Value
- Pass by Reference
🧠 Quick Check
See what you remember from the summary.
Which best describes aliasing?
🧠 Flashcards Preview
Tap a card to reveal the definition.
Ready to quiz yourself?
Test what you remember with a full practice quiz on this note. Create a free account and start in seconds.
Full Notes
Read the original note content before deciding whether to save or study from it.
Values, References and Aliasing
📘 Overview Aliasing occurs when multiple variables or access paths refer to the same object. Mutating that object can affect what every alias observes, whereas rebinding a variable changes only its own association. Assignment and parameter-passing behavior depend on the language's value and reference semantics.
🧠 Key Idea Copying a reference does not copy the referenced object. Distinguish changes to a shared object's state from changes to which object a variable refers to.
⚔️ Core Details: - A reference is a value that identifies an object rather than containing an independent copy of that object's data. - Value-copying semantics produce an independent copy of the assigned value; reference-copying semantics preserve access to the same object. - Aliasing exists when distinct variables or access paths designate the same object. - Mutation changes an existing object's state; rebinding changes a variable's association with a value or object. - A shallow copy creates a new outer object with shared nested references; a deep copy recursively duplicates the object structure according to the language or library's rules. - Pass-by-value can copy a reference into a parameter; pass-by-reference instead aliases the caller's variable itself.
🎯 Why It Matters: - Unexpected sharing can make a function alter data that its caller expected to remain unchanged. - Choosing between sharing and copying affects memory use, execution cost, and ownership of mutable data. - Immutable objects prevent mutation-related aliasing surprises without requiring every reference to identify a separate object. - Tests involving nested collections must distinguish an independent outer copy from independent nested contents.
🧠 Quick Recall: - Aliasing - Multiple variables or access paths designate the same object. - Identity versus equality - Identity means the same object; equality means equivalent content under the language's comparison rules. - Mutation versus rebinding - Mutation changes an object; rebinding changes a variable's association. - Shallow versus deep copy - Shallow copies can share nested objects; deep copies recursively duplicate the object structure. - Reference passed by value - Object mutation can be visible to the caller, but rebinding the parameter does not rebind the caller's variable.
More ways to study when you copy this note
Copy this note into your library to unlock focused practice sessions and long-term review.
Answer all questions first, then see feedback at the end — the way real exams work.
Focuses each session on what you got wrong, not what you already know.
Full timed exam with all questions, no pausing, and results at the end. Built for board exam prep.
Part of 🗄️ BS Information Systems — 1st Year
Browse this Review Set →More Computer Science notes
See all →More in Programming Fundamentals
See all →More from NoteLib
Browse NoteLib's public notes →Copy this note to your library and get the full Study Pack instantly — summary, key concepts, and practice quiz included.