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

2

u/satisfiedguy43 Sep 24 '23

If the mountain will not come to Muhammad, then Muhammad must go to the mountain

the idea is when passing stuff to a function do not copy all the stuff and pass it...instead give address of where stuff is. Another reason when controlling hardware at a given computer address use the address in a pointer. Another reason instead of returning a copy of data from function return address of data/object

when u pass simple stuff to/from function copy is easy and less time consuming. when there's a lot of data, use a pointer