Skip to the content ForoHackers
Log inJoin

Four years as a dev and I still do not understand pointers

C
#967 · anonymous · · Report

No name, because this is embarrassing.

I write mostly high-level languages. I got through interviews, I ship code, people think I am competent. But every time I read C and see **argv or int (*f)(int) my brain goes blank, and I nod in meetings.

Can someone explain it in a way that does not start with "it is simple"? I have read the chapters. I understand the words. I do not get the picture.

#1280 · anonymous · · Report

Memory is a long street of numbered mailboxes. A variable is a mailbox that holds a value. A pointer is a mailbox that holds the number of another mailbox.

int x = 7;      // mailbox containing 7
int *p = &x;    // mailbox containing the number of x's mailbox
*p = 9;         // go to that mailbox and put 9 in it

& means "the number of this mailbox", * means "go to that mailbox". **argv is just a mailbox holding the number of a mailbox that holds the number of a mailbox. Draw boxes and arrows on paper. Every C programmer did.

#1281 · anonymous · · Report

Seconded the drawing. And almost nobody here understood them at first, we just got used to nodding louder. Nothing embarrassing in asking.

Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply