Pointers Flashcards

1
Q

Pointer vs Reference

A

Reference: A reference is a variable that refers to something else and can be used as an alias for that something else.

Pointer: A pointer is a variable that stores a memory address, for the purpose of acting as an alias to what is stored at that address.

So, a pointer is a reference, but a reference is not necessarily a pointer. Pointers are a particular implementation of the concept of a reference, and the term tends to be used only for languages that give you direct access to the memory address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

C/C++ allows pointer arithmetic but Java Pointers (References) not:

A

The term “pointer” is strongly associated with the C/C++ concept of pointers, which are variables which store memory addresses and can be modified arithmetically to point to arbitrary addresses.
In Java, pointers only exist as an implementation detail for References. A copy of the reference is copied to the stack of a called function, pointing to the same object as the calling function and allowing you to manipulate that object. However you cannot change the object the calling function refers to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly