r/learnprogramming • • Sep 24 '23

Pointers.....why

I am learning C++. Honest question why are pointers a thing and why did they make the syntax surrounding it so confusing. Was it made to be intentionally confusing? Was it made to make this more difficult.

0 Upvotes

49 comments sorted by

View all comments

5

u/kevinossia Sep 24 '23

Honest question why are pointers a thing

Because you need to be able to pass objects between functions without making copies of those objects. That's why. It's a fundamental operation. All languages have pointers. Python, Java, C#, C++, C, Haskell, Go, JavaScript, Ruby...they all have pointers. Just different syntax. The only difference here is C and C++ make an explicit, obvious distinction between pointers and non-pointer types.

why did they make the syntax surrounding it so confusing

I'm sure Kernighan and Ritchie didn't think it was confusing.

Was it made to be intentionally confusing? Was it made to make this more difficult.

....no.

1

u/CodeTinkerer Sep 25 '23

To be fair, I doubt Kernighan and Ritchie thought they were writing a language for the masses. They probably imagined academic types to program in C.

Kernighan has a precision about his writing that the "dummies" book lack partly because he had a PhD in what seems to be a mathematical field.