0

I know primitives variables store values and obj variables store references. But technically is a primitive variable a reference to the location where the primitive value is in memory? B/c you have to know the location of the value.

chappie
  • 119
  • 4
  • 12
  • Yes ... and no. Yes(-ish) - because when a primitive is stored in variable in memory, the memory cell has a address. No for a number of reasons. 1) Variables are not always stored in memory. 2) The address of a variable is not constant; e.g. when the GC moves an object ... 3) The (instantaneous) address of a variable is not a *reference* in the sense that Java uses that term. – Stephen C Aug 21 '21 at 14:59
  • *B/c you have to know the location of the value.* - Actually, the location is "known" relative to something else; i.e. an object, a stack frame, or a class frame ... depending on what kind of variable you are talking about. – Stephen C Aug 21 '21 at 15:02
  • 1
    'Reference' is a technical word **defined by the programming language**, so in Java: no. In some other programming languages: yes. – user16632363 Aug 21 '21 at 15:57

0 Answers0