Pass-by-Value vs Reference

Debate on parameter passing semantics in languages like Python, Java, C, and C++, clarifying that they pass object references by value rather than true pass-by-reference.

📉 Falling 0.5x Programming Languages
1,975
Comments
19
Years Active
5
Top Authors
#6708
Topic ID

Activity Over Time

2008
5
2009
42
2010
38
2011
53
2012
74
2013
76
2014
57
2015
201
2016
79
2017
164
2018
306
2019
91
2020
90
2021
145
2022
154
2023
115
2024
151
2025
123
2026
11

Keywords

e.g PHP b.s TLDR JavaScript i.e GCC E.g wikipedia.org reference pass value pointers passed references java object semantics python

Sample Comments

guyzero Jan 13, 2011 View on HN

Why is passing a reference by value so hard to understand?

colanderman Dec 18, 2018 View on HN

Python (and Java) do not pass anything by reference. They pass by pointer-value. (If they passed by reference, you could change to which value a caller's variable was bound, like you can in C++).

user5994461 Apr 23, 2017 View on HN

Python is "pass reference by value", in C++ semantics.

jibal Sep 3, 2025 View on HN

Everything is passed by reference in Python. Everything is passed by value in C.

ethbr0 Mar 3, 2022 View on HN

Java pass by reference vs pass by value vs C pass by reference vs pass by value?

williamdclt Jan 25, 2018 View on HN

It's not even close, nothing is passed by reference!

jbooth Apr 29, 2017 View on HN

I'm still confused and I've been working in various languages for 15 years.If I pass a java object to a function, I'm passing a (probably) 8-byte pointer to some memory with a class tag, fields, whatever. It goes on the stack just like an 8 byte long.In languages that support pointers more directly, I'm doing the same thing, maybe minus the class tag in the pointed-to memory. Address is in an 8 byte type, put it on the stack and access the pointed-to struct in your ne

kremlin Mar 22, 2015 View on HN

Calling it "pass by value" without qualifying that, for objects, it passes the reference by value, is very confusing.

Kwpolska Apr 5, 2023 View on HN

Python's official reference might be more appropriate for this. But sometimes, even if things seem similar (e.g. both languages have variables), the semantics might be different. C/C++ has passing by value or by reference. Python and Java has neither, you can mutate the object, but you cannot reassign it (so you can't change the value of an int, but you can change some field of an object.

mattnewport Apr 15, 2024 View on HN

That's only because strings are immutable in Java. It's not true for reference types in general.In C++ passing a pointer by value is effectively the same as passing a reference, the only real difference being that the syntax for accessing the underlying value is more implicit for a reference.