What are the differences between Pointers and References?

what are the differences between Pointers and References?

Attached: 1545407186555.jpg (500x643, 60K)

Nm I figured it out.

Go be a cuck somewhere else

i'm op and that guy is not me

pointer is memory address, reference is thing memory address points to

what the fuck. can you kill yourself?

Attached: pointers.png (596x285, 201K)

A pointer is a reference to a memory address.
A reference is a pointer to memory address.

Maybe this will explain it better:
/ /Y o )( o Y\ \

It's a dog looking thru a mail slot?

one is gay the other is gay but one step below, you feel me.

If you're working with a C-like language, the trick with pointers is that the asterisk operator (*) means different things based on where it's used.

If you use it in a declaration, it means you're declaring a pointer, if you're using it otherwise it means you're retrieving the data at the address stored in the pointer. In other words, you grab the data referenced by the pointer, in other words dereference it.

Declaring a pointer - the address of an int will be stored in a. The int is stored at 0x100.

int* a = 0x100

Dereferencing pointer - the int stored AT address 0x100 will be stored in a.

int a = *0x100

This is just pseudocode, but it might not work in some less intelligent compilers because we need to cast 0x100 as a pointer. In other words, tell the compiler to treat the value 0x100 as an integer pointer so it does not give an error. In this case, we're using an asterisk as BOTH operators. Once to tell the compiler to treat the value as a pointer, and once to tell the compiler to dereference that value.

int a = *((int *)0x100);

So if we can dereference a pointer to get the value at that address, we can reference a variable to get the address at which is stored in the form of a pointer. That's exactly what the ampersand (&) operator does. It gets a pointer to whatever variable it operates on.

Referencing - in this example, the address of b will be stored in pointer a.

int b = 5;
int* a = &b;
printf("%d", *a); // prints 5
printf("%d", a); // if b is stored at, say 0x100 just to give an example, this will print the decimal value of 0x100


The above is a simplification - you can't necessarily print out an integer pointer as an integer ("%d") because the size of pointers depends on how many bytes your architecture uses to store addresses.

> Reference is abstract concept of a token through which you can access an object
> Pointer is a manifestation of that concept through the use of memory addresses

Attached: brainlette.png (211x239, 6K)

This, in a nutshell.

Attached: 1499476457227.png (694x262, 51K)

Don't feel bad if this takes a while to get. A lot of people need to look through this stuff a few times and sleep on it before they get it. One more complex example is below. It might make things click or make things more confusing.

Here we are dereferencing a pointer. Pointers are just addresses stored as variables, which means they have their own addresses at which they are stored which we can retrieve. "b" is a pointer to a pointer in this example - an address which points to an address at which data is stored.

int* a = 0x100;
int** b = &a;

>It's a dog looking thru a mail slot
I'm gunna use that later.

Attached: 1547532965212.png (352x159, 11K)

kinda looks like boobs through a mail slot to me.

>reference is thing memory address points to
data?

They can also reference pop culture and inside jokes.

based

*Here we are referencing a pointer

>you're fuckin with me

Quick Jow Forums, how do people get null pointer exceptions in languages without pointers?

Attached: 1546679745533.jpg (1427x1080, 223K)

The language can "abstract" the pointers in a way you still can get null pointers.

GJ