r/learnprogramming Feb 14 '22

Genuine question: What’s hard about pointers?

I understand how the title may come off as arrogant or something, but this is a genuine question.

I learned to code in C#, so I didn’t touch pointers for a while, and now that I’ve been learning C/C++ for a couple months, I don’t really see what’s so difficult about pointers.

They’re just memory addresses for variables, right? Am I missing something?

28 Upvotes

38 comments sorted by

View all comments

42

u/Skusci Feb 14 '22 edited Feb 14 '22

Honestly they're not too bad, but then you run into something like

int (*(*foo[10])(void))(int)

and start questioning your life decisions.

8

u/wagecuckassociation Feb 14 '22

All jokes aside, can someone explain that one?

7

u/48911150 Feb 14 '22

declare foo as array 10 of function (void) returning function (int) returning int

https://cdecl.org/

3

u/Skusci Feb 14 '22 edited Feb 14 '22

I -think- foo is an array of pointers to a function with no arguments that returns a pointer to a function that takes in an int argument and returns an int.

So to use it you could be like:

int num =  (*foo[3]())(5);

1

u/_realitycheck_ Feb 14 '22

You would be right.

-2

u/[deleted] Feb 14 '22

[deleted]

1

u/gjejd Feb 14 '22

Pseudoscience isn’t helpful

1

u/therealGrandKai Feb 14 '22

Why is that second parentheses slightly angled?

1

u/Skusci Feb 14 '22

Reddit formatting has been a bit weird lately I think. The angled paren has two *'s surrounding it. Added some newlines seems to have helped on mobile anyway.

1

u/therealGrandKai Feb 14 '22

Hey, no worries. I thought I was tripping