In order to set the value that a pointer points to, we dereference the pointer manually using the * operator...

>In order to set the value that a pointer points to, we dereference the pointer manually using the * operator. Inside of the method, t represents a pointer to a T value. By saying *t, we dereference the pointer t and we are able to access the value that t points to.


what

> not understanding how memory and pointers works.

kys.

never going to make it

You have some data. It is located in memory. Where it is located has an address i.e. a reference to your data.

This address is also data and can be stored in memory, at an address. This address is given a name (whatever you name your pointer variable)

You can access and/or alter data by dereferencing its address first to figure out where it is located in memory.

Hang in there senpai, you'll get there.

I never got why it's called dereferencing though. Isn't it just referencing the memory location in the pointer?

The pointer (address) is the "reference", and dereferencing is "following the reference". It's somewhat unintuitive terminology.

I didn't understand pointers for a long time and nothing anyone told me helped. Then eventually I figured it out and I don't really know why. So yeah, hang in there.

One thing: the syntax is good but it can be confusing at first. Even though we usually write int *a;, it makes more sense to think of it as int* a;. This defines a variable that can hold the address of an int (it can point to an int).

Anyway, keep looking at a bunch of diagrams with boxes and arrows, and keep looking at a bunch of code and writing a bunch of code that uses pointers.

Not really. It's almost like a box with some tape to seal it. You organize your things (values) using these boxes so that they are easy to find, but you need to open them (dereference) in order to use your value.

What are you learning right now OP?

best explanation/advice in thread, you musta a been a good dude to sit next to in class

>thinking the concept of pointers is the problem here
op is confused by the retarded terminology and excessively difficult explanation. Pointers work just the same as high-level variables except you can do math on the address itself, literally nobody could fail to understand pointers if explained in plain english instead of this academia bullshit

Ah, I get it. Dereferencing isn't removing a reference, it's just accessing the value stored in a pointer. Thank you Cred Forums.

That's a shitty-ass explanation, makes you wonder if the person who wrote it even understood pointers

on that note, how does anyone fail to understand pointers, assuming theyre familiar with variables, how cpu and memory work, and their confusion is not simply cascading from not getting the */& syntax? nobody with that basic knowledge could fail to, and if they do that means they dont gave that knowledge yet so i wonder why theyre already trying c.

>all this confusion ITT because of C languages having such shitty overreliance on pointers with such shitty syntax
oh am i laffin

this

one of my old teachers used to say that if you cant explain something in simple terms to a layman, you dont understand it yourself. as irrational as that sounds, i find it to be true

note that that isnt the same as making the layman actually understand it, which is a problem that too easily lies with the layman

Why not call it access, open, check, basically anything that doesn't read like 'removed'? Fucken terminology.

It's an explanation meant for someone who already understands it.


/* function: */

T value = 2; //some value.
T *t = &value; //POINT t TO value. This is NOT a copy of value.

T copyVal = *t; //Get value (not the pointer -- what it points to) and store in copyVal.

*t = 5; //value is now 5.
//copyVal is still 2.

>why not call it access
Consider Ada, if you will:

Some_Pointer : access Integer;

...

Some_Pointer := new Integer (7);
Some_Pointer.all := 3;


...and so forth.

>basic knowledge
Lacking in most CS courses.
They're designed to churn out code monkeys, not humans who understand.

>that picture
wtf am i looking at

Makes perfect sense tbqh

...

Mmm, Ada.

"Dereference" seem like a confusing word to use for it if I'm understanding it correctly.