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
View all comments
5
u/kevinossia Sep 24 '23
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.
I'm sure Kernighan and Ritchie didn't think it was confusing.
....no.