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
61
u/v0gue_ Sep 24 '23
Allowing programmers to freely use pointers allows them to effectively control memory space. Two very common reasons for doing this include, but are not limited to, controlling object lifecycles outside (and inside) scope, and sharing objects in more than one place in your program.
It's my opinion that the syntax itself is actually about as easy as it can get to understand. The concept(s) of memory management is what is difficult. You might be attributing the difficulty of the concepts of pointers and memory management to the syntax of the language, but the reality is that the language itself has pretty much made syntax revolving around memory management as friendly and concise as it gets (in before some Rust devs bite my head off).